我有两个班级:
@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个