My problem. I got this Mapper
List<NotificationEmail> getAllErrorNotifications();
and this is part of my Mapper xml
<select id = "getAllErrorNotifications" resultMap = "NotificationEmailResultMap">
...
<choose>
<when test = "notification.maxRetry != null">
(n.NOT_RETRY_COUNT IS NULL OR n.NOT_RETRY_COUNT <= n.NOT_MAX_RETRY)
</when>
<otherwise>
(n.NOT_RETRY_COUNT IS NULL OR n.NOT_RETRY_COUNT <= 6)
</otherwise>
</choose>
I get this error org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'notification.maxRetry != null'. Cause: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "maxRetry")
When I needed to use if or when usually I passed my "notification" as a method param... but now I cannot do that. My NotificationEmail class got this:
private Notification notification;
(inside it got my maxRetry).
I know that my sql n.NOT_MAX_RETRY should be not null. How can I fix this?
In the end I found and alternative way with just sql
WHERE
...
(n.NOT_MAX_RETRY IS NOT NULL AND
(n.NOT_RETRY_COUNT IS NULL OR n.NOT_RETRY_COUNT <= n.NOT_MAX_RETRY)
OR
(n.NOT_MAX_RETRY IS NULL AND
(n.NOT_RETRY_COUNT IS NULL OR n.NOT_RETRY_COUNT <= 6)
))
basically I made a xor based on NOT_MAX_RETRY IS NULL or IS NOT NULL in an and condition so that they are mutually exclusive. The second part is an OR condition that should be true. So if n.NOT_RETRY_COUNT IS NULL basically it will pass both with n.NOT_MAX_RETRY null and not null... if n.NOT_RETRY_COUNT is not null it will pass only if <= 6 (if max_retry is null) xor if <= max_retry.
I think that's a good solution.