Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How does one initialize a BLOB/CLOB in JPA?

843830Jul 2 2008 — edited Jul 2 2008
Folks,

JPA allows mapping of CLOB / BLOB data types. But these data types are interfaces and the implementations are vendor specific. Is there a standard way defined in JPA to initialize these types.

I know we can map blobs / clobs as byte[] / String but I'm not interested in that solution as its not scalable. I want to use java.sql.Blob and java.sql.Clob as the java type.

Lets say, if I define an entity that has an attribute of type java.sql.Blob if I stick with JPA, I can only initialize it to null. Even after I save the entity and retrieve it back again (using hibernate), the value of this attribute remains null, which means I cannot read / write this attribute. Does JPA specify that the value of java.sql.Blob, java.sql.Clob fields should be initialized to a non-null value after the entity is saved for the first time, to allow it to be manipulated. (ie. is hibernate not JPA compliant here?)

One way to workaround this issue in hibernate is to initialize this field with the return value from Hibernate.createBlob(new byte[0]). Once I save that entity, I can then get a java.sql.Blob implementation that I can use to read/write this field. However, this means that I have a dependency on vendor implementation, which is undesirable.

Does JPA specify a standard way for BLOB/CLOB initialization or do we have a gap in the specification. I read through the JSR 220 and searched around, but didn't find anything specific. Will appreciate clarifications from the experts on this list or pointers to any pages that might clarify this aspect of JPA.

Cheers,
Aj
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 30 2008
Added on Jul 2 2008
0 comments
1,550 views