Reputation: 892
I have following scenario:
1) A abstract @MappedSuperClass with composite PK:
@MappedSuperclass
@EqualsAndHashCode(of = { "id" }, callSuper = false)
public abstract class LocalizedDetail {
private static final long serialVersionUID = 1L;
@EmbeddedId
@Getter
@Setter
private LocalePK id;
(...)
2) This is my 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 sub class:
@Entity
@Table(name = "BT_VALUE_OBJECT_INFO")
public class ValueObjectInfo extends LocalizedDetail {
(...)
4) Generating JPA meta model through maven using org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor plugin.
What is happening is that LocalePK metamodel is being generated without any attributes:
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(LocalePK.class)
public abstract class LocalePK_ {
}
But if I set this LocalePK as a composite PK of any other entity that does not extends LocalizedDetail it is generated correctly. I need to create a "fake" entity class just to generate this metamodel.
Is there any known limitation to this model to generate correct PK meta-model?
Thanks,
Upvotes: 2
Views: 2995
Reputation: 181
Actually, I found a solution for this updating to Version 5.4.23. I hope this works for anyone more.
Upvotes: 0
Reputation: 9
According to Java Persistence with Hibernate, Second Edition
@MappedSuperClass
is not a good way to do this. Consider using
@Inheritance(stragety = TABLE_PER_CLASS)
instead.
Upvotes: 0
Reputation: 848
This looks to be a bug with the current hibernate jpa modelgen. The reference may be found here (https://hibernate.atlassian.net/browse/HHH-8714). I found that is also true for Hibernate 5.2
A current work-around that I've done is to swop out the hibernate jpa model gen for the eclipse-link one, while still using the hibernate library.
I've tested with the main hibernate libraries that I use.
The outcome is fully constructed classes, but it also generates the superclass _ file for the extends.
I've found when using this superclass in the criteria api (e.g. AbstractBaseEntity vs InheritingEntity) the fields are not populated and are always null.
Always make sure to reference the typed attribute through the inheriting class.
e.g. InheritingEntity.createdTime_
Hoping this helps in some way?,
Kind Regards,
```
<!-- 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>
```
Upvotes: 1