【问题标题】:OneToOne shared Primary Key, Pure JPA 2.0 Solution works with EclipseLink but fails with with Hibernate ProviderOneToOne 共享主键,Pure JPA 2.0 解决方案与 EclipseLink 一起使用,但与 Hibernate Provider 一起使用失败
【发布时间】:2013-07-24 10:01:58
【问题描述】:

请参考 OneToOne between two tables with shared primary key 原来的问题。

我在同一线程中的回答是关于纯 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

有什么想法吗?

【问题讨论】:

    标签: hibernate jpa-2.0 eclipselink one-to-one shared-primary-key


    【解决方案1】:

    这是因为旧的 Hibernate 版本确实有一个错误,在 HHH-5695 中有很好的描述并在 HHH-6813 中修复。

    问题可以通过更新到fresh version来解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-30
      • 1970-01-01
      • 2010-09-20
      • 1970-01-01
      • 2012-05-29
      相关资源
      最近更新 更多