<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=adeveloper" rel="nofollow">Jack Woods</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7895?redirect=false" rel="nofollow">SPR-7895</a></strong> and commented</p>
<p dir="auto">Custom message converters registered with AnnotationMethodHandlerAdapter are not used, only the default ones registered with &lt;mvc:annotation-driven /&gt; are used. I found that the setMessageConverters() method of AnnotationMethodHandlerAdapter class is called two times, one for the default and another one for the bean defined in the spring xml file. The one defined in the spring xml file is never used when doing actual marshalling and unmarshalling.</p>
<p dir="auto">For example the following jibx message converter is not used:</p>
<p dir="auto">&lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;<br>
&lt;property name="messageConverters"&gt;<br>
&lt;util:list id="beanList"&gt;<br>
&lt;ref bean="marshallingHttpMessageConverter" /&gt;<br>
&lt;/util:list&gt;<br>
&lt;/property&gt;<br>
&lt;/bean&gt;<br>
&lt;bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;<br>
&lt;constructor-arg ref="jixbUserMarshaller" /&gt;<br>
&lt;property name="supportedMediaTypes" value="text/xml" /&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">&lt;oxm:jibx-marshaller id="jixbUserMarshaller" target-class="com.company.restpoc.model.User" /&gt;</p>
<p dir="auto">In my opinion the jibx support in Spring OXM is rather poor. We need to define a separate converter for each target-class. We don't need to do that kind of thing when using Jersey with Jibx. We just need two <code class="notranslate">@Provider</code> classes that implement MessageBodyReader and MessageBodyWriter. I have attached JIBXBodyReader and JIBXBodyWriter for your reference.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://forum.springframework.org/showthread.php?t=100244" rel="nofollow">http://forum.springframework.org/showthread.php?t=100244</a></p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/17533/JIBXBodyReader.java" rel="nofollow">JIBXBodyReader.java</a> (<em>1.41 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/17532/JIBXBodyWriter.java" rel="nofollow">JIBXBodyWriter.java</a> (<em>1.57 kB</em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=frank" rel="nofollow">Frank Titius</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2406?redirect=false" rel="nofollow">SPR-2406</a></strong> and commented</p>
<p dir="auto">If you try to persist a new object (insert) with duplicate key you get:</p>
<p dir="auto">org.springframework.dao.InvalidDataAccessResourceUsageException: Could not invoke JDO makePersistent(Object) method; nested exception is javax.jdo.JDODataStoreException: Insert request failed: INSERT INTO <code class="notranslate">ACCOUNT</code> (<code class="notranslate">CITY</code>,<code class="notranslate">STATUS</code>,<code class="notranslate">PHONE</code>,<code class="notranslate">COUNTRY</code>,<code class="notranslate">EMAIL</code>,<code class="notranslate">LANGUAGE_PREFERENCE</code>,<code class="notranslate">LAST_NAME</code>,<code class="notranslate">ZIP</code>,<code class="notranslate">ADDRESS2</code>,<code class="notranslate">USERID</code>,<code class="notranslate">ADDRESS1</code>,<code class="notranslate">FIRST_NAME</code>,<code class="notranslate">PASSWORD</code>) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)<br>
NestedThrowables:<br>
java.sql.SQLException: Duplicate entry 'a' for key 2<br>
Caused by: javax.jdo.JDODataStoreException: Insert request failed: INSERT INTO <code class="notranslate">ACCOUNT</code> (<code class="notranslate">CITY</code>,<code class="notranslate">STATUS</code>,<code class="notranslate">PHONE</code>,<code class="notranslate">COUNTRY</code>,<code class="notranslate">EMAIL</code>,<code class="notranslate">LANGUAGE_PREFERENCE</code>,<code class="notranslate">LAST_NAME</code>,<code class="notranslate">ZIP</code>,<code class="notranslate">ADDRESS2</code>,<code class="notranslate">USERID</code>,<code class="notranslate">ADDRESS1</code>,<code class="notranslate">FIRST_NAME</code>,<code class="notranslate">PASSWORD</code>) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)<br>
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:412)<br>
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2379)<br>
at org.jpox.store.StoreManager.insert(StoreManager.java:775)<br>
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3512)<br>
at org.jpox.state.StateManagerImpl.makePersistent(StateManagerImpl.java:3485)<br>
at org.jpox.AbstractPersistenceManager.internalMakePersistent (AbstractPersistenceManager.java:1146)<br>
at org.jpox.AbstractPersistenceManager.makePersistent(AbstractPersistenceManager.java:1201)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:585)<br>
at org.springframework.orm.jdo.JdoTemplate$9.doInJdo(JdoTemplate.java:406)<br>
at org.springframework.orm.jdo.JdoTemplate.execute(JdoTemplate.java:259)<br>
at org.springframework.orm.jdo.JdoTemplate.makePersistent(JdoTemplate.java:403)<br>
at improvit.web.skill.dao.jdo.JdoAccountDao.storeAccount(JdoAccountDao.java:48)<br>
at improvit.web.skill.dao.jdo.JdoAccountDao.insertAccount(JdoAccountDao.java:52)<br>
at improvit.web.skill.domain.logic.WebSkillImpl.insertAccount(WebSkillImpl.java:111)<br>
at improvit.web.skill.test.dao.AbstractAccountDaoTests.testDuplicateAccount(AbstractAccountDaoTests.java:123)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:585)<br>
at junit.framework.TestCase.runTest(TestCase.java:154)<br>
at junit.framework.TestCase.runBare(TestCase.java:127)<br>
at improvit.web.skill.test.dao.ConditionalTestCase.runBare(ConditionalTestCase.java:69)<br>
at junit.framework.TestResult$1.protect(TestResult.java:106)<br>
at junit.framework.TestResult.runProtected(TestResult.java:124)<br>
at junit.framework.TestResult.run(TestResult.java:109)<br>
at junit.framework.TestCase.run(TestCase.java:118)<br>
at junit.framework.TestSuite.runTest(TestSuite.java:208)<br>
at junit.framework.TestSuite.run(TestSuite.java:203)<br>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)<br>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)<br>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)<br>
NestedThrowablesStackTrace:<br>
java.sql.SQLException: Duplicate entry 'a' for key 2<br>
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)<br>
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)<br>
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1124)<br>
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)<br>
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:773)<br>
at org.jpox.store.rdbms.ParamLoggingPreparedStatement.execute(ParamLoggingPreparedStatement.java:213)<br>
at org.jpox.store.rdbms.request.Request.executeUpdate(Request.java:88)<br>
at org.jpox.store.rdbms.request.InsertRequest.execute(InsertRequest.java:283)<br>
at org.jpox.store.rdbms.table.ClassTable.insert(ClassTable.java:2379)<br>
at org.jpox.store.StoreManager.insert(StoreManager.java:775)<br>
at org.jpox.state.StateManagerImpl.internalMakePersistent(StateManagerImpl.java:3512)<br>
at org.jpox.state.StateManagerImpl.makePersistent(StateManagerImpl.java:3485)<br>
at org.jpox.AbstractPersistenceManager.internalMakePersistent(AbstractPersistenceManager.java:1146)<br>
at org.jpox.AbstractPersistenceManager.makePersistent(AbstractPersistenceManager.java:1201)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:585)<br>
at org.springframework.orm.jdo.JdoTemplate$9.doInJdo(JdoTemplate.java:406)<br>
at org.springframework.orm.jdo.JdoTemplate.execute(JdoTemplate.java:259)<br>
at org.springframework.orm.jdo.JdoTemplate.makePersistent(JdoTemplate.java:403)<br>
.... (rest omitted)</p>
<p dir="auto">A "duplicate key" error should be translated to a DataIntegrityViolationException.<br>
Possible cause: First JPOX wraps a JDODataStoreException around the SQLException.<br>
Than reflection wrapped an InvocationTargetException and in JdoTemplate.makePersistent(..) the InvocationTargetException is caught which will prevent the translation in JdoTemplate.execute(..).</p>
<p dir="auto">Possible solution for ALL "catch (InvocationTargetException ex) " in JdoTemplate:</p>
<ul dir="auto">
<li>
<p dir="auto">before:<br>
catch (InvocationTargetException ex) {<br>
throw new InvalidDataAccessResourceUsageException(<br>
"Could not invoke JDO makePersistentAll(Collection) method", ex.getTargetException());<br>
}</p>
</li>
<li>
<p dir="auto">after:<br>
catch (InvocationTargetException ex) {<br>
if (ex.getTargetException() instanceof JDOException)<br>
throw (JDOException) ex.getTargetException();<br>
else<br>
throw new InvalidDataAccessResourceUsageException(<br>
"Could not invoke JDO makePersistentAll(Collection) method", ex.getTargetException());<br>
}</p>
</li>
</ul>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.2.8, 2.0 RC2, 2.0 RC3</p>