请参阅具有共享主键的两个表之间的OneToOne对于最初的问题。
我在同一个线程中回答了纯JPA 2.0方式的解决方案(使用EclipseLink Provider)。
现在我面临的问题是,一旦我将JPA提供者从EclipseLink切换到hibernate entitymanager 3.5.1-Final,同样的例子是抛出以下异常:
2 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.1-Final
11 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.1-Final
13 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
15 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
17 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
94 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
99 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.5.1-Final
269 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.nirmal.demo.jpa.eclipselink.domain.UserLogin
298 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.nirmal.demo.jpa.eclipselink.domain.UserLogin on table USER_LOGIN
341 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.nirmal.demo.jpa.eclipselink.domain.UserDetail
342 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.nirmal.demo.jpa.eclipselink.domain.UserDetail on table USER_DETAIL
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: users] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.nirmal.demo.jpa.eclipselink.Main.main(Main.java:16)
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: com.nirmal.demo.jpa.eclipselink.domain.UserLogin.userDetail, referenced property unknown: com.nirmal.demo.jpa.eclipselink.domain.UserDetail.userLogin
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:152)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1221)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:383)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1449)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1077)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:275)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:359)
... 4 more
有什么想法吗?
这是因为旧的Hibernate版本确实有一个错误,在HHH-5695中进行了很好的描述,并在HHH-6813中进行了修复。
问题可以通过更新到新版本来解决。