0

i hava a @MappedSuperclass VoBusinessObject which contains the id and version

`

@MappedSuperclass
@javax.persistence.TableGenerator(name = "VoBusinessObjectIdGenerator", table = "UidTable", pkColumnName = "object", valueColumnName = "nextHiValueColumn", pkColumnValue = "object", allocationSize = 10)
public class VoBusinessObject
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    public Integer getId() {
        return this.id;
    }
@Version
    @Column(name = "version", nullable = false)
    public Integer getVersion() {
        return this.version;
    }

`

All Entities extend VoBusinessObject and so they inherit id and version.

When i deploy my app to wildfly 8.2 i get

Caused by: java.lang.IllegalArgumentException: expecting IdClass mapping
    at org.hibernate.jpa.internal.metamodel.AttributeFactory$3.resolveMember(AttributeFactory.java:979) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.internal.metamodel.AttributeFactory$4.resolveMember(AttributeFactory.java:1018) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.internal.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:466) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.internal.metamodel.AttributeFactory.buildAttribute(AttributeFactory.java:93) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.internal.metamodel.MetadataContext.wrapUp(MetadataContext.java:256) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.internal.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:96) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.internal.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:148) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:867) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
    at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]

Then i tried to annotate all entities with

@IdClass(VoBusinessObject.class)

followed by

Caused by: org.hibernate.AnnotationException: Unable to define @Version on an embedded class: de.itwiesner.hannymede.common.valueobjects.VoBusinessObject
    at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1734) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:2632) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.AnnotationBinder.bindIdClass(AnnotationBinder.java:2719) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.AnnotationBinder.mapAsIdClass(AnnotationBinder.java:1041) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:781) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]

what is the right way to map my inheritance?

best regards

Heiko

Heiko Wiesner
  • 65
  • 3
  • 13
  • Do you add an `@Id` mapping to any subclass of `VoBusinessObject`? You might look at [the answer here](http://stackoverflow.com/questions/12930935/illegalargumentexception-expecting-idclass-mapping). – Brian Vosburgh Feb 17 '15 at 01:53
  • Hello Brian, i have seen this post, but i don't have compound keys. – Heiko Wiesner Feb 17 '15 at 09:50

1 Answers1

0

the problem was an @ID in a subclass. Annoying, that Hibernate does not tell the Entity where it happens.

best regards

Heiko

Heiko Wiesner
  • 65
  • 3
  • 13