对于原始问题,请参阅 两个具有共享主键的表之间的 OneToOne 。
我在同一个线程中回答了纯 JPA 2.0 方式的解决方案(使用 EclipseLink 提供程序)。
现在我面临的问题是,一旦我将 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
有任何想法吗?