JPA @MappedSuperclass和JPAMetaModelEntityProcessor

JPA @MappedSuperclass和JPAMetaModelEntityProcessor

问题描述:

我有以下情形:JPA @MappedSuperclass和JPAMetaModelEntityProcessor

1)一种抽象@MappedSuperclass复合PK:

@MappedSuperclass 
@EqualsAndHashCode(of = { "id" }, callSuper = false) 
public abstract class LocalizedDetail { 

    private static final long serialVersionUID = 1L; 

    @EmbeddedId 
    @Getter 
    @Setter 
    private LocalePK id; 
(...) 

2)这是我的PK:

@Embeddable 
@EqualsAndHashCode 
@AllArgsConstructor 
@NoArgsConstructor 
public class LocalePK implements Serializable { 

    private static final long serialVersionUID = 1L; 

    @Column(name = "ID", length = 256) 
    @Getter 
    @Setter 
    private String id; 

    @Column(name = "LOCALE", length = 16) 
    @Getter 
    @Setter 
    private String locale; 

} 

3) LocalizedDetail子类:

@Entity 
@Table(name = "BT_VALUE_OBJECT_INFO") 
public class ValueObjectInfo extends LocalizedDetail { 
(...) 

4)使用org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor插件通过maven生成JPA元模型。

正在发生的事情是正在没有任何属性生成LocalePK元模型:

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor") 
@StaticMetamodel(LocalePK.class) 
public abstract class LocalePK_ { 


} 

但如果我设置LocalePK为做任何其他实体的复合PK不延伸LocalizedDetail它正确生成。我需要创建一个“假”实体类来生成这个元模型。

该模型是否有任何已知的限制来生成正确的PK元模型?

谢谢,

这看起来是一个与当前hibernate jpa modelgen的错误。参考可以在这里找到(https://hibernate.atlassian.net/browse/HHH-8714)。 我发现这也适用于休眠5.2

我所做的一个当前的解决方法是淘汰eclipse-link的hibernate jpa模型gen,同时仍然使用hibernate库。

我已经用我使用的主要hibernate库进行了测试。

结果是完全构建的类,但它也为扩展生成超类_文件。 我在标准api中使用这个超类时发现(例如AbstractBaseEntity vs InheritingEntity),这些字段没有填充,并且始终为空。 始终确保通过继承类引用已键入的属性。 例如InheritingEntity.createdTime_

希望这有助于以某种方式?

亲切的问候,

```

<!-- Hibernate --> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>5.2.12.Final</version> 
     <type>jar</type> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>5.4.2.Final</version> 
     <type>jar</type> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-annotations</artifactId> 
     <version>3.5.6-Final</version> 
     <type>jar</type> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate.javax.persistence</groupId> 
     <artifactId>hibernate-jpa-2.1-api</artifactId> 
     <version>1.0.0.Final</version> 
     <type>jar</type> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-c3p0</artifactId> 
     <version>5.2.12.Final</version> 
     <type>jar</type> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.eclipse.persistence</groupId> 
     <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> 
     <version>2.7.0</version> 
    </dependency> 

    <!-- 
     Cant use hibernate jpa model gen cause of https://hibernate.atlassian.net/browse/HHH-8714 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-jpamodelgen</artifactId> 
     <version>5.2.12.Final</version> 
     <type>jar</type> 
     <scope>test</scope> 
    </dependency>--> 

    <dependency> 
     <groupId>jaxen</groupId> 
     <artifactId>jaxen</artifactId> 
     <version>1.1.6</version> 
     <type>jar</type> 
     <scope>test</scope> 
    </dependency> 

```

+0

是的,很有意义!我会标记你的答案是正确的,以帮助其他人。谢谢! PS:我改变了我的实体结构,因此这个问题不再发生。 –