Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
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
Eclipse UserFriend
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 messageGo to next message
Eclipse UserFriend
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
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 11:18 Go to previous messageGo to next message
Eclipse UserFriend
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 12:51 Go to previous message
Eclipse UserFriend
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: Sat May 17 13:16:24 EDT 2025

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

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

Back to the top