Persisting XML with OpenJPA

Tags: , , , , , , , , , ,

I’ve been looking at JPA - Java Persistence Architecture and decided to play a bit with OpenJPA using DB2 as the back-end. My goal: to persist and query XML data in DB2, making use of DB2’s pureXML capabilities to query the XML data using SQL/XML’s XMLQUERY() function.

However, while OpenJPA has an extensive documentation, the examples are not always complete and there isn’t a lot of information on the web regarding OpenJPA error determination and solving. So, here are some recommendations for some of the problems I have encountered. The class xml.Address is the one to be persisted as XML in the database using JPA and it is stored as the field shipAddress of the Order objects.

 [java] Exception in thread “main” <openjpa-1.0.0-r420667:568756 fatal user error>
org.apache.openjpa.persistence.ArgumentException:
Type “class xml.Address” does not have persistence metadata. 

Suggestion: Remove the reference to xml.Address from persistence.xml

[java] Exception in thread “main” <openjpa-1.0.0-r420667:568756 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException:
Encountered unmanaged object “xml.Address@9b2a51″ in
persistent field “xml.Order.shipAddress” of managed object “xml.Order@12b3349″
during flush.  However, this field does not allow cascade persist. 
You cannot flush unmanaged objects.
  [java] FailedObject: xml.Address@9b2a51

Suggestion: Make sure you have no @Entity or @Embeddable annotations in xml.Address. The main annotation is @XmlRootElement.

 [java] Exception in thread “main” <openjpa-1.0.0-r420667:568756 fatal general error>
org.apache.openjpa.persistence.PersistenceException:
“xml” doesnt contain ObjectFactory.class or jaxb.index

Suggestion: add a file jaxb.index into your xml package containing all the classes to be persisted as XML: a file containing Address in our case.

Popularity: 57% [?]

2 Comments »

DB2 on Mac

Tags: , , , , , , ,

Last week, after my presentation at University of Minho about the DB2 on Campus and DB2 Student Ambassador programs and the pureXML features in DB2, one student came to me and asked me if DB2 was available for Mac. My answer was a ‘no’, but things will change pretty soon. 

My ‘office neighbor’ Antonio Cangiano just made public IBM’s intention of releasing a DB2 Express-C port to Intel Mac. This is one more big step from DB2 Express-C towards the community, after very open licensing conditions, Ruby on Rails driver and adapter, soon-to-come Python and Django driver and adapter, DB2 Express-C orum and DB2 Express-C blog, etc….

 

Popularity: 29% [?]

No Comments »

Close
E-mail It