java - Use JPA @StaticMetamodel classes WITHOUT a local persistence.xml? (Remote EJB) -
java - Use JPA @StaticMetamodel classes WITHOUT a local persistence.xml? (Remote EJB) -
i'm trying utilize jpa service remotely via ejb easycriteria's detached criteria generator (very cool feature) not require entitymanager write query.
easycriteria<mytable> mycriteria = easycriteriafactory.createeasycto(); mycriteria.leftjoin(mytable_.othertable.getname());
essentially, not want ejb client server aware of database, other schema (so no persistence.xml or data-source.) want utilize metamodel enforce schema name safety on these queries. schema (entities , metamodel) imported via maven dependency.
<dependency> <groupid>my.service</groupid> <artifactid>my-schema</artifactid> <version>1.1.1-snapshot</version> </dependency>
this jar contains both jpa entities , @staticmetamodel classes, example
@generated(value = "org.hibernate.jpamodelgen.jpametamodelentityprocessor") @staticmetamodel(myclass.class) public abstract class myclass_ { public static volatile singularattribute<myclass, string> descr; }
however, although myclass (the entity) , myclass_ (the metamodel) available @ compile time, metamodel myclass_ throws npe @ runtime. debugger says "class not loaded", seems odd. there special these classes cause them not load? need other dependency?
this happens junit test, it's not container issue seems.
make sure myclass_ class goes classpath , in jar.
when using maven how can it:
generate meta-model:
<plugin> <groupid>org.bsc.maven</groupid> <artifactid>maven-processor-plugin</artifactid> <executions> <execution> <id>process</id> <goals> <goal>process</goal> </goals> <phase>generate-sources</phase> <configuration> <outputdirectory>${basedir}/target/generated-sources/java/</outputdirectory> <processors> <processor>org.hibernate.jpamodelgen.jpametamodelentityprocessor </processor> </processors> </configuration> </execution> </executions> </plugin>
now meta-model located in target/generated-sources/java/ in order add together them src/main/java need to:
<plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>build-helper-maven-plugin</artifactid> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/target/generated-sources/java</source> </sources> </configuration> </execution> </executions> </plugin>
java hibernate maven jpa
Comments
Post a Comment