I am using JPA 2.0 in my project.
I have and entity subclass
Code:
AppEntity extends AbstractEntity
.
Code:
AbstractEntity
is mapped with
Code:
@MappedSuperClass
, which has
@Id
@Column(name ="OBJID")
private String objId;
@Column
...(other entities)
along with getters and setters for objId and other attributes.
In my subclass AppEntity all the setter methods are overridden. subclass entity does not have any attributes (@Id / @Column mappings).
When I deploy this application using hibernate 4.2.6
I get ArrayIndexOutOfBoundException because org.hibernate.cfg.AnnotationBinder checks for at server startup
Code:
private static PropertyData getUniqueIdPropertyFromBaseClass(
.....
//Id properties are on top and there is only one
return baseClassElements.get( 0 );
}
Since the subclass entity does not have any attributes get(0) throws Outofbound exception.
But the above code work in JPA 1.0 since hibernate 3.5 does not have above check.
In JPA 2.0 is there any restrictions on subclass entities? What logic behind checking the attributes in AnnotationBinder.java getUniqueIdPropertyFromBaseClass method.
https://github.com/hibernate/hibernate-orm/blob/4.2/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
Adding StackTrace for reference
Code:
AnnotationBinder.getUniqueIdPropertyFromBaseClass(PropertyData, PropertyData, AccessType, Mappings) line: 2576
AnnotationBinder.isIdClassPkOfTheAssociatedEntity(ElementsToProcess, XClass, PropertyData, PropertyData, AccessType, Map<XClass,InheritanceState>, Mappings) line: 925
AnnotationBinder.mapAsIdClass(Map<XClass,InheritanceState>, InheritanceState, PersistentClass, EntityBinder, PropertyHolder, ElementsToProcess, Set<String>, Mappings) line: 824
AnnotationBinder.bindClass(XClass, Map<XClass,InheritanceState>, Mappings) line: 671
Configuration$MetadataSourceQueue.processAnnotatedClassesQueue() line: 3533
Configuration$MetadataSourceQueue.processMetadata(List<MetadataSourceType>) line: 3487
Configuration.secondPassCompile() line: 1376
Configuration.buildSessionFactory(ServiceRegistry) line: 1777
EntityManagerFactoryImpl.<init>(PersistenceUnitTransactionType, boolean, Class, Configuration, ServiceRegistry, String) line: 94
Ejb3Configuration.buildEntityManagerFactory(BootstrapServiceRegistryBuilder) line: 920
Ejb3Configuration.buildEntityManagerFactory() line: 904
HibernatePersistence.createContainerEntityManagerFactory(PersistenceUnitInfo, Map) line: 92
PersistenceUnitServiceImpl.createContainerEntityManagerFactory() line: 200
PersistenceUnitServiceImpl.access$600(PersistenceUnitServiceImpl) line: 57
PersistenceUnitServiceImpl$1.run() line: 99
ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
ThreadPoolExecutor$Worker.run() line: 908
JBossThread(Thread).run() line: 619
JBossThread.run() line: 122