Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » When Oracle converts empty string to null, does EclipseLink cache reflect that?
When Oracle converts empty string to null, does EclipseLink cache reflect that? [message #386576] Thu, 02 April 2009 07:31 Go to next message
Torben Putkonen is currently offline Torben PutkonenFriend
Messages: 34
Registered: July 2009
Member
Some databases - like Oracle - store empty strings as null, whereas some
databases differentiate between null and empty string. This is causing us
an issue.

First we persist using TopLink Essentials an entity, which has an empty
string as one field. Oracle converts this value to null when it stores it.

However, when I fetch the entity, TopLink returns it from the cache, where
this field is still an empty string. EclipseLink doesn't seem to know,
that what got stored into the database was actually a null value, and this
incoherency is causing problems - testing if a field is null value fails
because an empty string is returned from the cache.

Naturally it is not difficult to handle these cases in the application
level, but it would be nice if we didn't need to take into account
behaviour of different RDBMS.

We are considering upgrading from TopLink to EclipseLink. Is EclipseLink
capable of updating its cache according to what actually got stored to the
database, or is there any other way to tackle this issue?
Re: When Oracle converts empty string to null, does EclipseLink cache reflect that? [message #386580 is a reply to message #386576] Thu, 02 April 2009 13:00 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You should be able to define a nullValue in your direct/basic mappings to
translate null to empty string. You could also set the default null value
for String to empty string in your Session's ConversionManager.

You could also use a ReturningPolicy (@ReturnInsert, @ReturnUpdate) to
refresh a value back from the database on a write.

Or just handle having null and empty string mean the same thing in your
app.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: When Oracle converts empty string to null, does EclipseLink cache reflect that? [message #386585 is a reply to message #386580] Fri, 03 April 2009 06:52 Go to previous messageGo to next message
Torben Putkonen is currently offline Torben PutkonenFriend
Messages: 34
Registered: July 2009
Member
Thanks James,

ReturningPolicy is exactly what I was looking for!

Is the ConversionManager documented somewhere? I found information about
it in TopLink documentation, but not in EclipseLink. The class seems to
belong to org.eclipse.persistence.internal.helper package, but this
package is not included in the API javadocs.
Re: When Oracle converts empty string to null, does EclipseLink cache reflect that? [message #386593 is a reply to message #386585] Mon, 06 April 2009 14:04 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Actually the ConversionManager API is exposed on the DatasourceLogin
object,

http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persi stence/sessions/DatasourceLogin.html#setDefaultNullValue(java.lang.Class,%20java.lang.Object)

You can set it using a SessionCustomizer,

session.getLogin().setDefaultNullValue(String.class, "");

---
James


James : Wiki : Book : Blog : Twitter
Re: When Oracle converts empty string to null, does EclipseLink cache reflect that? [message #1808115 is a reply to message #386576] Mon, 17 June 2019 15:18 Go to previous messageGo to next message
thorsten kruse is currently offline thorsten kruseFriend
Messages: 6
Registered: October 2017
Junior Member
Using eclipselink 2.7.4 I noticed this behaviour using login.setDefaultNullValue(String.class, "");

Let us say an Employee entity has a String field called idCardNumber. I use a ReadAllQuery to get all Employees having unset idCardNummer, conformResultsInUnitOfWork is set, too:

ExpressionBuilder eb = new ExpressionBuilder();
Expression isNullExp = eb.get("idCardNumber").isNull();

ReadAllQuery raq = new ReadAllQuery(Employee.class);
raq.setSelectionCriteria(isNullExp);
raq.conformResultsInUnitOfWork();

Executing the query gives the expected Employees, say a number of 10. Just next step executing the query again results in no Employees. When debugging the second query executing shows the cached Emplyoee.idCardNummer field is set to "" when executing the query the first time.

Is this a bug? Should setDefaultNullValue(String.class, "") treat null and "" equally in cache?
Re: When Oracle converts empty string to null, does EclipseLink cache reflect that? [message #1808182 is a reply to message #1808115] Tue, 18 June 2019 16:51 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I may be the minority, but I wouldn't consider it a bug. The setDefaultNullValue is only for reading in values and was meant for converting the data into primitive java types which do not allow nulls, back when primitives were more common.

You can file a feature to have the in-memory conforming functionality to look at it, but I personally wouldn't want it to; Such a feature would need to consider the default value as null and nulls as the default value, adding overhead to all queries, when if I really want non-null comparisons to be made, I can add it to the query directly.
Previous Topic:No [EntityType] was found for the key class in the Metamodel
Next Topic:Error Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd
Goto Forum:
  


Current Time: Fri Mar 29 06:24:27 GMT 2024

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

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

Back to the top