我使用Netbeans 8.0.1创建了两个Maven项目来说明问题:common1和common2(jars)。
庸俗的:
包pck1
@MappedSuperclass
public class Entity1 implements Serializable {
@Basic(optional = false)
@Column(name = "val")
protected String val;
}
包pck2
@Entity
@Table(name = "entity2")
public class Entity2 extends Entity1 {
@Id
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="PU-1" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ent</groupId>
<artifactId>common1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
common2
包pck3
@Entity
@Table(name = "entity3")
public class Entity3 extends Entity1 {
@Id
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="PU-2" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ent</groupId>
<artifactId>common2</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.ent</groupId>
<artifactId>common1</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.5.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
在构建过程之后,我在Netbeans中看到了带有规范元模型的生成源:
庸俗的
包pck1
@Generated(value="EclipseLink-2.5.2.v20140319-rNA", date="2014-11-11T13:39:25")
@StaticMetamodel(Entity1.class)
public class Entity1_ {
public static volatile SingularAttribute<Entity1, String> val;
}
包pck2
@Generated(value="EclipseLink-2.5.2.v20140319-rNA", date="2014-11-11T13:39:25")
@StaticMetamodel(Entity2.class)
public class Entity2_ extends Entity1_ {
public static volatile SingularAttribute<Entity2, Long> id;
}
common2
包pck3
@Generated(value="EclipseLink-2.5.2.v20140319-rNA", date="2014-11-11T13:39:31")
@StaticMetamodel(Entity3.class)
public class Entity3_ {
public static volatile SingularAttribute<Entity3, Long> id;
}
问题是为什么Entity3_没有将Entity1_扩展为Entity2_?我做错了什么?
答案 0 :(得分:1)
我有同样的问题。这似乎是我正在使用的Eclipse Link 2.5.0.v20130507库中的一个错误。由于我在JBoss中使用了hibernate,因此切换到了Hibernate 4.3.8。使用hibernate-jpamodelgen库正确生成元模型类。
答案 1 :(得分:1)
没错,它只是EclipseLink注释处理器不够聪明 我看到你也在EclipseLink论坛上问过,没有答案......也许你应该提出一个问题(有人会接受吗?祝你好运!)。
但是,我使用EclipseLink 2.6.0作为持久性提供程序,但我让hibernate-jpamodelgen生成了元模型:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>${eclipselink.version}</version>
<scope>provided</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.eclipse.persistence</groupId> -->
<!-- <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> -->
<!-- <version>${eclipselink.version}</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.10.Final</version>
<scope>provided</scope>
</dependency>
和以前一样,不需要maven-processor-plugin,只需要依赖开关。
尽管如此,我的 个人 建议是完全转移到休眠状态(这是我将尽快做的事情)因为更广泛,更现实社区。 p>