어노테이션을 사용하여 일대일 관계를 시도하고 있습니다.
이것은 코드입니다.org.hibernate.AnnotationException : 알 수없는 mappedBy in 오류 :
package test.hibernate;
@Entity
@Table(name="EMPLOYEE")
public class Employee {
@Id
@GeneratedValue
@Column(name="EMP_ID")
private Long empID;
@Column(name="fName")
private String fName;
@Column(name="lName")
private String lName;
@OneToOne(mappedBy="employee", cascade=CascadeType.ALL)
private Address address;
public Employee(/* Long empID, */String fName, String lName) {
super();
// this.empID = empID;
this.fName = fName;
this.lName = lName;
}
public Employee() {
super();
}
public Long getEmpID() {
return empID;
}
public void setEmpID(Long empID) {
this.empID = empID;
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
package test.hibernate;
@NamedNativeQueries({ @NamedNativeQuery(name = "addressQuery", query = "from Address", resultClass = Address.class) })
public class Address {
@Column(name = "EMP_ID")
@GenericGenerator(name = "gen", strategy = "foreign", parameters = @Parameter(name = "property", value = "employee"))
private Long empID;
@Column(name = "ADDRESS")
private String address;
@Column(name = "CITY")
private String city;
@OneToOne
@PrimaryKeyJoinColumn
private Employee employee;
public Address() {
super();
// TODO Auto-generated constructor stub
}
public Address(/* Long empID, */String address, String city) {
super();
// this.empID = empID;
this.address = address;
this.city = city;
}
public Long getEmpID() {
return empID;
}
public void setEmpID(Long empID) {
this.empID = empID;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
}
}
나는 다음과 같은 예외가 점점 오전 :
Hibernate one to many (XML Mapping)
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.AnnotationException: Unknown mappedBy in: test.hibernate.Employee.address, referenced property unknown: test.hibernate.Address.employee
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:129)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1127)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283)
at test.hibernate.HibernateUtil.openSession(HibernateUtil.java:14)
at test.hibernate.Test.main(Test.java:11)
Exception in thread "main" java.lang.NullPointerException
at test.hibernate.HibernateUtil.openSession(HibernateUtil.java:19)
at test.hibernate.Test.main(Test.java:11)
내 코드에 어떤 문제가 있습니까? 누군가 도울 수 있습니까?
주소 클래스를 게시하십시오. – Rafa
그리고 "알 수없는 속성 unknown : test.hibernate.Address.employee"라는 오류 메시지를 읽으십시오. –
Yori, 저는 이미 Address 클래스를 게시했습니다. 이제는 Employee와 분리되었습니다. – Aniket