CSS

Tuesday, April 30, 2013

JodaTime jadira.usertype.autoRegisterUserTypes in a persistence jar

So I have had no problem using UserType to have Joda Time objects in my JEE project when it was in a WAR.  I then took the war and made it into an EAR with all of the JPA classes in their own JAR.  The persistence.xml file was in this JAR.  When I started up the application in JBOSS 7.1.1 I got the following error.

Could not determine type for: org.jadira.usertype.dateandtime.joda.PersistentDateTime

This is what I did to fix it. In my pom.xml I made sure the Usertype.core depedency was there and most importanly I made sure that the manifest had it in the classpath.  You add the classpath to the manifest by adding addClasspath to the compiler plugin.   I also added jadira.usertype.autoRegisterUserTypes to the persistence.xml file. Here are some snippets:

 pom.xml

        <dependency>
            <groupId>org.jadira.usertype</groupId>
            <artifactId>usertype.core</artifactId>
        </dependency>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <archive>
                        <manifest>
                               <addClasspath>true</addClasspath>
                         </manifest>
                    </archive>               
                    
                    <compilerarguments>
                        <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                    </compilerarguments>
                </configuration>
            </plugin>

persistence.xml

   <persistence-unit name="primary" transaction-type="JTA">
      <!-- If you are running in a production environment, add a managed 
         data source, the example data source is just for proofs of concept! -->
      <jta-data-source>java:jboss/datasources/myyfu</jta-data-source>
      <non-jta-data-source>java:jboss/datasources/myyfu</non-jta-data-source>
      <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
      <properties>
         <!-- Properties for Hibernate -->
        <property name="hibernate.hbm2ddl.auto" value="validate" />
        <property name="hibernate.show_sql" value="${hibernate.show_sql}" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect"/>
        <property name="hibernate.default_schema" value="YFUALFA"/>
        <property name="hibernate.cache.use_second_level_cache" value="true" />
        <property name="hibernate.cache.use_query_cache" value="true" />
        <property name="hibernate.default_batch_fetch_size" value="25"/>     
        <property name="org.hibernate.envers.track_entities_changed_in_revision" value="true"/>     
        <property name="jadira.usertype.autoRegisterUserTypes" value="true" />
     </properties>
   </persistence-unit>

No comments:

Post a Comment