Friday, February 27, 2015

Exception in thread "main" org.hibernate.MappingException: Cannot use identity column key generation with mapping for:


Exception in thread "main" org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: com.varasofttech.pojo.table_per_concrete_class.PermanentEmployee
    at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:96)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at com.varasofttech.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:36)
at com.varasofttech.util.HibernateUtil.getSessionFacoty(HibernateUtil.java:22)
at com.varasofttech.client.Application.main(Application.java:22)
Entity:
@Entity
@Table(name="Persons")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
// some other properties
}
Problem:
Hibernate does not support the use of identity or increment generation strategy for "table per concrete class with union strategy".

@Entity
@Table(name="Persons")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private long id;
// some other properties

}

0 comments: