Eclipselink生成的规范元模型不会从另一个jar扩展基本元模型 [英] Eclipselink generated canonical metamodel doesn't extend base metamodel from another jar

查看:116
本文介绍了Eclipselink生成的规范元模型不会从另一个jar扩展基本元模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Netbeans 8.0.1创建了两个Maven项目来说明一个问题:common1和common2(罐子).

I created two Maven projects using Netbeans 8.0.1 to illustrate a problem: common1 and common2 (jars).

common1:

软件包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

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

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中看到了具有规范元模型的生成源:

After build process I see generated sources with canonical metamodels in Netbeans:

common1

软件包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_?我在做什么错了?

The question is why Entity3_ not extends Entity1_ as Entity2_? What am I doing wrong?

推荐答案

没错,只是EclipseLink注释处理器不够聪明.
我也看到您也在EclipseLink论坛上问到了,也没有答案...也许您应该提出一个问题(有人会接受吗?祝您好运!).

Nothing wrong, it's just EclipseLink annotation processor is not clever enough.
I see you asked on EclipseLink forum too, with no answer... Maybe you should file an issue (will someone ever take it? good luck!).

但是,我使用EclipseLink 2.6.0作为持久性提供程序,但我让hibernate-jpamodelgen代替了生成元模型:

However, I'm using EclipseLink 2.6.0 as persistence provider, but I let hibernate-jpamodelgen generate the metamodel instead:

<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,只需依赖项开关即可.

like before, no maven-processor-plugin is needed, just the dependency switch.

尽管如此,由于社区越来越广泛,我的 个人 建议是完全休眠(这就是我将尽快采取的行动).

Nevertheless, my personal advice is to move to hibernate completely (that's what I'll do ASAP) because of a wider and more present community.

这篇关于Eclipselink生成的规范元模型不会从另一个jar扩展基本元模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆