2017-08-15 78 views
1

我有以下情形: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元模型?

謝謝,

回答

0

這看起來是一個與當前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:我改變了我的實體結構,因此這個問題不再發生。 –