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 03:31 Go to next message
Torben Putkonen is currently offline Torben Putkonen
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 09:00 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
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 02:52 Go to previous messageGo to next message
Torben Putkonen is currently offline Torben Putkonen
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 10:04 Go to previous message
James Sutherland is currently offline James Sutherland
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
Previous Topic:EclipseLink Logo Contest
Next Topic:java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be
Goto Forum:
  


Current Time: Wed Aug 27 15:16:20 EDT 2014

Powered by FUDForum. Page generated in 0.02880 seconds