Use JPA @StaticMetamodel classes without local persistence.xml? (Remote EJB)

I am trying to use the JPA service remotely through EJB using the EasyCriteria isolated criteria generator (a very cool feature) that does not require EntityManager to write a request.

EasyCriteria<MyTable> myCriteria = EasyCriteriaFactory.createEasyCTO();
myCriteria.leftJoin(MyTable_.otherTable.getName());

Essentially, I don’t want the EJB client server to know about a database other than a schema (so there is no persistence.xml or a data source.) But I want to use Metamodel to ensure the security of schema names in these queries. The schema (objects and metamodel) is imported through a dependency on Maven.

<dependency>
    <groupId>my.service</groupId>
    <artifactId>my-schema</artifactId>
    <version>1.1.1-SNAPSHOT</version>
</dependency>

This jar contains both JPA entities and @StaticMetamodel classes, for example

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(MyClass.class)
public abstract class MyClass_ {
    public static volatile SingularAttribute<MyClass, String> descr;

}

, MyClass () MyClass_ () , MyClass_ NPE . " ", . - , ? ?

JUnit, .

+4
1

, MyClass_ , , .

Maven :

  • :

    <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>
    
  • / /java/so, src/main/java, :

    <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>            
    
0

Source: https://habr.com/ru/post/1546190/


All Articles