JPA 2.0 메타 모델을 생성하는 방법은 무엇입니까?
CriteriaQuery JPA 2.0 과 관련된 유형 안전성의 정신 으로 엔티티의 메타 모델 표현 을 지원하는 API도 있습니다 .
메타 모델 클래스를 수동으로 생성하는 대신 메타 모델을 생성하기 위해이 API의 완전한 기능 구현을 알고있는 사람이 있습니까? 누군가 Eclipse에서 이것을 설정하는 단계를 알고 있다면 멋질 것입니다 (나는 주석 프로세서를 설정하는 것만 큼 간단하다고 가정하지만 결코 알 수 없습니다).
편집 : Hibernate JPA 2 Metamodel Generator를 우연히 발견했습니다 . 그러나 항아리에 대한 다운로드 링크를 찾을 수 없기 때문에 문제가 남아 있습니다.
편집 2 :이 질문을 한 후 잠시 지났지 만 돌아와서 SourceForge 의 Hibernate JPA Model Generator 프로젝트에 대한 링크를 추가 할 것이라고 생각했습니다.
누군가 Eclipse에서 이것을 설정하는 단계를 알고 있다면 멋질 것입니다 (주석 프로세서를 설정하는 것만 큼 간단하다고 가정하지만 결코 알 수 없습니다)
네, 그렇습니다. 다음은 다양한 JPA 2.0 구현에 대한 구현 및 지침입니다.
EclipseLink
최대 절전 모드
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
- http://in.relation.to/2009/11/09/hibernate-static-metamodel-generator-annotation-processor
OpenJPA
org.apache.openjpa.persistence.meta.AnnotationProcessor6
- http://openjpa.apache.org/builds/2.4.1/apache-openjpa/docs/ch13s04.html
DataNucleus
org.datanucleus.jpa.JPACriteriaProcessor
- http://www.datanucleus.org/products/accessplatform_2_1/jpa/jpql_criteria_metamodel.html
최신 Hibernate 구현은 다음에서 구할 수 있습니다.
이전 Hibernate 구현은 다음과 같습니다.
jpa-metamodels-with-maven-example을 살펴보십시오 .
최대 절전 모드
- 우리는
org.hibernate.org:hibernate-jpamodelgen
. - 프로세서 클래스는
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
입니다.
종속성으로서의 최대 절전 모드
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${version.hibernate-jpamodelgen}</version>
<scope>provided</scope>
</dependency>
프로세서로서의 최대 절전 모드
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<compilerArguments>-AaddGeneratedAnnotation=false</compilerArguments> <!-- suppress java.annotation -->
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${version.hibernate-jpamodelgen}</version>
</dependency>
</dependencies>
</plugin>
OpenJPA
- 우리는
org.apache.openjpa:openjpa
. - 프로세서 클래스는
org.apache.openjpa.persistence.meta.AnnotationProcessor6
입니다. - OpenJPA는 추가 요소가 필요한 것 같습니다
<openjpa.metamodel>true<openjpa.metamodel>
.
종속성으로서의 OpenJPA
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Aopenjpa.metamodel=true</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
프로세서로서의 OpenJPA
<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>
<processors>
<processor>org.apache.openjpa.persistence.meta.AnnotationProcessor6</processor>
</processors>
<optionMap>
<openjpa.metamodel>true</openjpa.metamodel>
</optionMap>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>${version.openjpa}</version>
</dependency>
</dependencies>
</plugin>
EclipseLink
- 우리는
org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor
. - 프로세서 클래스는
org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
입니다. - EclipseLink에는
persistence.xml
.
종속성으로서의 EclipseLink
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<scope>provided</scope>
</dependency>
프로세서로서의 EclipseLink
<plugins>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>
</processors>
<compilerArguments>-Aeclipselink.persistencexml=src/main/resources-${environment.id}/META-INF/persistence.xml</compilerArguments>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>${version.eclipselink}</version>
</dependency>
</dependencies>
</plugin>
DataNucleus
- 우리는
org.datanucleus:datanucleus-jpa-query
. - 프로세서 클래스는
org.datanucleus.jpa.query.JPACriteriaProcessor
입니다.
종속성으로서의 DataNucleus
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-jpa-query</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
프로세서로서의 DataNucleus
<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>
<processors>
<processor>org.datanucleus.jpa.query.JPACriteriaProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-jpa-query</artifactId>
<version>${version.datanucleus}</version>
</dependency>
</dependencies>
</plugin>
Dali ( "JEE 개발자 용 Eclipse IDE"에 포함됨)를 통한 Eclipse의 JPA 2.0 지원에는 Eclipse와 통합 된 자체 메타 모델 생성기가 있습니다.
- Select your project in the Package Explorer
- Go to Properties -> JPA dialog
- Select source folder from Canonical metamodel (JPA 2.0) group
- Click Apply button to generate metamodel classes in the selected source folder
This should work on any JPA provider as the generated classes are standard.
Also see here.
For eclipselink, only the following dependency is sufficient to generate metamodel. Nothing else is needed.
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
For Hibernate as provider which is most common IMHO:
In case of build tools like Gradle, Maven you need to have Hibernate JPA 2 Metamodel Generator jar in the classpath and compiler level>=1.6 that is all you need build the project and metamodel will be generated automatically.
In case of IDE Eclipse 1. goto Project->Properties->Java Compiler->Annotation Processing and enable it. 2. Expand Annotation Processing->Factory Path-> Add External Jar add Hibernate JPA 2 Metamodel Generator jar check the newly added jar and say OK. Clean and Build done!
Link Hibernate JPA 2 Metamodel Generator jar link from maven repo https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen
참고URL : https://stackoverflow.com/questions/3037593/how-to-generate-jpa-2-0-metamodel
'developer tip' 카테고리의 다른 글
중괄호를 사용하여 Python에서 집합 초기화 (0) | 2020.09.12 |
---|---|
디버깅을 위해 생성기 객체를 목록으로 변환 (0) | 2020.09.12 |
Xcode 4에서 릴리스 / 배포 용으로 빌드하려면 어떻게해야합니까? (0) | 2020.09.12 |
std :: move ()는 어떻게 값을 RValues로 전송합니까? (0) | 2020.09.12 |
ListView에서 바닥 글을 추가하는 방법은 무엇입니까? (0) | 2020.09.11 |