我在我的项目中使用JPA 2.0。
我和实体子类AppEntity扩展了AbstractEntity。
AbstractEntity与@MappedSuperClass一起映射,它具有
@Id
@Column(name ="OBJID")
private String objId;
@Column
...(other entities)
along with getters and setters for objId and other attributes.
在我的子类AppEntity中,所有setter方法都被覆盖。 子类实体没有任何属性(@Id / @Column映射)。
使用hibernate 4.2.6部署此应用程序时
我得到ArrayIndexOutOfBoundException,因为org.hibernate.cfg.AnnotationBinder在服务器启动时检查
private static PropertyData getUniqueIdPropertyFromBaseClass(
.....
//Id properties are on top and there is only one
return baseClassElements.get( 0 );
}
由于子类实体没有任何属性,get(0)抛出Outofbound异常。
但是上面的代码在JPA 1.0中起作用,因为hibernate 3.5没有上面的检查。
在JPA 2.0中是否对子类实体有任何限制? 检查AnnotationBinder.java getUniqueIdPropertyFromBaseClass方法中的属性背后的逻辑。
添加StackTrace以供参考
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