Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » What is the point of setNullValue
What is the point of setNullValue [message #1754540] Mon, 20 February 2017 00:38
Jared Walker is currently offline Jared WalkerFriend
Messages: 1
Registered: February 2017
Junior Member

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.
Previous Topic:Many databases, same shared schema. One EntityManagerFactory?
Next Topic:Does it possible to make "alter online table" queries in mysql/mariadb
Goto Forum:

Current Time: Tue Mar 31 02:53:55 GMT 2020

Powered by FUDForum. Page generated in 0.01973 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top