我有一个@MappedSuperclass VoBusinessObject,其中包含id和版本
`
@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;
}
`
所有实体都扩展了VoBusinessObject,因此它们继承了id和版本。
当我将我的应用程序部署到wildfly 8.2时,我得到了
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]
然后我尝试使用
注释所有实体@IdClass(VoBusinessObject.class)
接着是
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]
映射我的继承的正确方法是什么?
最好的问候
的Heiko
答案 0 :(得分:0)
问题是子类中的@ID。 令人讨厌的是,Hibernate没有告诉实体它发生在哪里。
最好的问候
的Heiko