<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vitor Rodrigues &#187; openjpa</title>
	<atom:link href="http://www.vitorrodrigues.com/blog/tag/openjpa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vitorrodrigues.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 28 Sep 2009 18:05:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Persisting XML with OpenJPA</title>
		<link>http://www.vitorrodrigues.com/blog/2007/10/23/persisting-xml-in-openjpa/</link>
		<comments>http://www.vitorrodrigues.com/blog/2007/10/23/persisting-xml-in-openjpa/#comments</comments>
		<pubDate>Tue, 23 Oct 2007 18:15:46 +0000</pubDate>
		<dc:creator>vitor</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[db2express-c]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[mapping]]></category>
		<category><![CDATA[openjpa]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[purexml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.vitorrodrigues.com/blog/2007/10/23/persisting-xml-in-openjpa/</guid>
		<description><![CDATA[I&#8217;ve been looking at JPA &#8211; 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&#8242;s pureXML capabilities to query the XML data using SQL/XML&#8216;s XMLQUERY() function. However, while OpenJPA has an extensive documentation, the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking at <a href="http://java.sun.com/javaee/overview/faq/persistence.jsp">JPA &#8211; Java Persistence Architecture</a> and decided to play a bit with <a href="http://openjpa.apache.org">OpenJPA </a>using <a href="http://www.ibm.com/db2/express">DB2 </a>as the back-end. My goal: to persist and query XML data in DB2, making use of DB2&#8242;s <a href="http://www.ibm.com/software/data/db2/9/editions_features_purexml.html%20">pureXML </a>capabilities to query the XML data using <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=35341">SQL/XML</a>&#8216;s XMLQUERY() function.
</p>
<p>However, while OpenJPA has an <a href="http://openjpa.apache.org/docs/latest/manual/manual.html">extensive documentation</a>, the examples are not always complete and there isn&#8217;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 <em>xml.Addres</em>s is the one to be persisted as XML in the database using JPA and it is stored as the field <em>shipAddress </em>of the <em>Order </em>objects.<br />
  
</p>
<pre> [java] Exception in thread "main" &lt;openjpa-1.0.0-r420667:568756 fatal user error&gt;
org.apache.openjpa.persistence.ArgumentException:
Type "class xml.Address" does not have persistence metadata.&nbsp;
</pre>
<p><strong>Suggestion:</strong> Remove the reference to <em>xml.Address</em> from <em>persistence.xml</em>.&nbsp;
</p>
<pre>[java] Exception in thread "main" &lt;openjpa-1.0.0-r420667:568756 nonfatal user error&gt;
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.&nbsp; However, this field does not allow cascade persist.&nbsp;
You cannot flush unmanaged objects.
  [java] FailedObject: xml.Address@9b2a51
</pre>
<p><strong>Suggestion</strong><strong>:</strong> Make sure you have no <em>@Entity</em> or <em>@Embeddable</em> annotations in <em>xml.Address</em>. The main annotation is <em>@XmlRootElement</em>.
</p>
<pre> [java] Exception in thread "main" &lt;openjpa-1.0.0-r420667:568756 fatal general error&gt;
org.apache.openjpa.persistence.PersistenceException:
"xml" doesnt contain ObjectFactory.class or jaxb.index
</pre>
<p><strong>Suggestion</strong><strong>:</strong> add a file <em>jaxb.index</em> into your <em>xml </em>package containing all the classes to be persisted as XML: a file containing <em>Address</em> in our case.</p>
<img src="http://www.vitorrodrigues.com/blog/?ak_action=api_record_view&id=116&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.vitorrodrigues.com/blog/2007/10/23/persisting-xml-in-openjpa/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

