1

我在我的项目中使用 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 映射)。

当我使用休眠 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 方法中的属性背后的逻辑是什么。

https://github.com/hibernate/hibernate-orm/blob/4.2/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java

添加 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 
4

0 回答 0