Hibernate Caused by: org.hibernate.AnnotationExcep

2019-06-07 07:51发布

问题:

I have two classes :

@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
    }

and

@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
}

But when i start my server i have the following error : Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: com.startup.app.models.entities.Profil.avatar, referenced property unknown: com.startup.app.models.entities.Avatar.profil at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:153) at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1639) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1393) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1868) at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247) at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373) at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479) ... 126 more

回答1:

This is a bug in Hibernate, see the description here - HHH-5695. It was fixed together with this bug HHH-6813 in 4.2.2. Try upgrading to that version and see if the problem remains.