openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Broadhead <matthew.broadh...@nbmlaw.co.uk>
Subject @Converter @Strategy @Externalizer @Factory multiple fail?
Date Thu, 14 Sep 2017 22:26:44 GMT
i am using TomEE 7.0.3 which ships with OpenJPA 2.4.2.  the database is 
MySQL

i want to store a String (MySQL text column) in the database but use 
JAXB to marshal and unmarshal the POJOs.  the main class is annotated 
with @XmlRootElement. it is also serializable, as are the children objects.

i tried to use javax.persistence.Converter specifically 
javax.persistence.AttributeConverter but it just gives
org.apache.openjpa.persistence.ArgumentException - No registered 
metadata for type "class 
uk.me.kissy.sales.entities.jpa.LeadScriptConverter". This can happen if 
this class has not been annotated as a persistent entity or specified in 
the persistence unit (ex: in the orm.xml).
i had the class listed in the persistence.xml.  maybe 2.4.2 is only JPA 2.0?

then i found this article 
https://rmannibucau.wordpress.com/2015/06/18/openjpa-and-serialization-or-how-to-replace-attributeconverterof-jpa-2-1-in-jpa-2-0/

and tried Romain's suggestion using @Externalizer and @Factory 
(org.apache.openjpa.persistence.Externalizer and 
org.apache.openjpa.persistence.Factory).  This results in
Caused by: java.io.StreamCorruptedException: invalid stream header: 
3C71756F.  with and without @Persistent annotating the field

at the bottom of the article i found Struberg's suggestion 
https://github.com/rsandtner/openjpa-converter/blob/master/src/main/java/com/github/rsandtner/openjpaconverter/JodaTimeValueHandler.java

and 
https://github.com/rsandtner/openjpa-converter/blob/master/src/test/resources/META-INF/persistence.xml#L61.

this loads the POJO correctly but fails to commit the object back to the 
database during em.merge and em.persist.  there is a gist here 
https://gist.github.com/chongma/5510953224939ef9871ff6197de992e6

FYI i am using the deltaspike 1.8.0 @Transactional 
org.apache.deltaspike.jpa.api.transaction.Transactional to wrap the 
transactions in case that might be interfering.



Mime
View raw message