Hibernate引起:org.hibernate.AnnotationException:未知的mappedBy

时间:2014-03-17 21:40:42

标签: hibernate mapping

我有两个班级:

@Entity
@Table(name="profil")
public class Profil {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="id")
    private long id;


    @OneToOne(mappedBy="profil")
    private Avatar avatar;

+ getters and setters
    }

@Entity
@Table(name="avatar")
public class Avatar {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="id")
    private Long id;


    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="profil_id")
    private Profil profil;
+getters and setters
}

但是当我启动服务器时出现以下错误: 引起:org.hibernate.AnnotationException:未知的mappedBy in:com.startup.app.models.entities.Profil.avatar,引用的属性unknown:com.startup.app.models.entities.Avatar.profil     在org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:153)     在org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1639)     在org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1393)     在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)     在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1868)     在org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)     在org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373)     在org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)     ......还有126个

1 个答案:

答案 0 :(得分:1)

这是Hibernate中的一个错误,请参阅此处的说明 - HHH-5695。它与4.2.2中的错误HHH-6813一起修复。尝试升级到该版本,看看问题是否仍然存在。