Reputation: 570
Please refer OneToOne between two tables with shared primary key for the original problem.
And my answer in the same thread about a solution in Pure JPA 2.0 way (using EclipseLink Provider).
Now the issue I am facing is that once I switched the JPA provider from EclipseLink to hibernate-entitymanager 3.5.1-Final, Same example is throwing below exception:
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
Any ideas?
Upvotes: 0
Views: 1518
Reputation: 42084
That is because of old Hibernate version which does have a bug well described in HHH-5695 and fixed in HHH-6813.
Problem can be solved by updating to fresh version.
Upvotes: 0