I am working on a project that is being converted to use eclipselink after many years of using a old version of TOPLink. I've noticed a difference in behavior between the versions, but in subsequent testing I'm not even sure the feature is useful.
This concerns the method setNullValue() for the Descriptor.
Here is the Descriptor for the field ACTIVE:
// active mapping
ObjectTypeMapping objectTypeMapping = new ObjectTypeMapping();
In TOPLink the following code:
ExpressionBuilder builder = new ExpressionBuilder(ToolRoleInstance.class);
ReportQuery query = new ReportQuery(ToolRoleInstance.class, builder);
Expression approvedExpression = builder.get("active").equal(true);
List<ReportQueryResult> results = (List<ReportQueryResult>)dbReader.executeQuery(query);
ReportQueryResult result = results.get(0);
Number count = (Number) result.get("COUNT");
System.out.println("count is " + count);
Produces the following query:
SELECT COUNT(*) FROM toolRoleInstance WHERE (ACTIVE = ?)
bind => [T]
count is 1450
The same execution in Eclipselink produces:
SELECT COUNT(toolRoleInstanceID) FROM toolRoleInstance WHERE (ACTIVE = ?)
bind => [null]
count is 0
I see three problems with this code:
1. There is a behavior change between TOPLink and EclipseLink
2. The query should possibly have two conditions (ACTIVE = 'T' OR ACTIVE IS NULL)
3. The substitution in eclipselink should probably handle null values appropriately (i.e. the query should be IS NULL instead of = NULL
So, is there usefulness in setNullValue? What is the intended use as it seems that we are not using it correctly.
At this point, I'm thinking of taking the non-lazy road and removing setNullValue from our descriptors and setting the appropriate values in the database. This means I'll also have to inspect places where those objects are created and set a default value.
Any advice or insight into why things operate as they do would be appreciated.