cancel
Showing results for 
Search instead for 
Did you mean: 

Storing empty Strings in Entity with JPA

Former Member
0 Kudos

Hello Community,

i'm working on a migration of an application to nwds and web-dynpro.

i read data from my old database and want to insert it into the new database.

for that i have two beans, which each using an entity representing the source and the destination data.

when i want to use the persist Method of the Entity-Manager of JPA to persist the data, which was read from the old database, i get some exceptions telling me, that the data of one database-column is an empty string and that jpa cannot assign an empty string.

here some relevant lines of the exceptions:

javax.persistence.PersistenceException: Failed to set value for field >>tabvalue<< of entity >>com.huelsta.kall.entities.RefTable<<.
Exception of type com.sap.sql.log.OpenSQLException caught: Cannot assign an empty string to host variable 4..

But my applications must handle empty strings!!!

Any ideas who to handle that problem are very welcome.

regards

matthias hayk

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hello,

thanx for your quick answer.

Your recommendation has (unfortunately) another big drawback. My applications uses the Java Dictionary! This is because in that dictionary the can be defined simple-types. this data from that definitions is used in wd-verification-actions and is on the other side a big advance.

But using Java-Dictionary means using the System-Datasource, also means using OpenSQL.

But i simply dont understand the reason of the restrictions.

regards

matthias hayk

Former Member
0 Kudos

Hello,

of course something like this is possible. i realized this at the moment in such a way using the getter- and setter-methods.

but this should not be!

in all apps in know (including sql itself) it is normal to use empty strings. in sql this would be something like "update table <xyz> set mycolumn='' where id =4711". and an empty string is simply not the same as a null value.

addtionaly i had to find out, that there is also a problem when an string simple ends with blank. so if an objectpropery which is to persist using jpa in sap has the value "abc " an opensql-excetion is raised, telling that the string must not end with a Blank. Even if i could agree to this special issue, i dont aggree in, that it is not possible to persist empfy strings.

any other opinions are welcome

regards

matthias

Former Member
0 Kudos

Hi Matthias,

Another option is, of course, not to use Open SQL, but Native SQL or Vendor SQL, as the unavailability for empty strings storage is a drawback of the Open SQL only (at least - as far as I know).

More information about using Vendor SQL and Native SQL with JPA: http://help.sap.com/saphelp_nwce10/helpdata/en/2d/23b32e8c0152469edf07909703fe03/frameset.htm

I hope that helps!

Regards,

Yordan

Former Member
0 Kudos

Hi Matthias,

I am not a Java developer, so I cannot tell you how exactly you can handle this by means of some source code example...

If you first assign a 'null' to the empty string (i.e. check if a string is empty; if so, make it equal to 'null'), and then try to persist it, you should not get those exceptions any more.

I hope that helps!

Regards,

Yordan