重複の可能性:
Hibernate の問題 - 「マップされていないクラスをターゲットとする @OneToMany または @ManyToMany の使用」
SpringでHibernateプロジェクトを統合していますが、プロジェクトに1対多を追加するとエラーが発生しました
ユーザー.java
@Entity
@Table(name = "UserLogin")
public class User implements Serializable {
private static final long serialVersionUID = -3652559447682574722L;
private int id;
private String username;
private String password;
private Set<EmployeeLeave> leaveInfo = new HashSet<EmployeeLeave>();
public User() {
}
public User(String username, String password, int id) {
this.username = username;
this.password = password;
this.id = id;
}
@Column(name = "username", nullable = false)
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "password", nullable = false)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "User(" + username + ")";
}
public String UserAuthentification() {
return "Success";
}
/*
* @OneToMany(cascade = CascadeType.ALL)
*
* @JoinTable(name = "employee_leave", joinColumns = { @JoinColumn(name = "id") }, inverseJoinColumns = {
*
* @JoinColumn(name = "employeeId") })
*/
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user")
public Set<EmployeeLeave> getLeaveInfo() {
return leaveInfo;
}
public void setLeaveInfo(Set<EmployeeLeave> leaveInfo) {
this.leaveInfo = leaveInfo;
}
}
Employeeleave.java
@Entity
@Table(name = "employeeLeave")
public class EmployeeLeave implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private Long employeeId;
private Date startDate;
private Date endDate;
private String reason;
private Long totalSickLeave;
private Long totalPaidoffLeave;
private String status = "Waiting";
private User user;
@Id
@Column(name = "employeeId")
public Long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
@Column(name = "startdate", nullable = false)
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@Column(name = "enddate", nullable = false)
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
@Column(name = "reason", nullable = false)
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@Column(name = "totalsickleave", nullable = false, columnDefinition = "bigint default 15")
public Long getTotalSickLeave() {
return totalSickLeave;
}
public void setTotalSickLeave(Long totalSickLeave) {
this.totalSickLeave = totalSickLeave;
}
@Column(name = "totalpaidoffleave", nullable = false, columnDefinition = "bigint default 15")
public Long getTotalPaidoffLeave() {
return totalPaidoffLeave;
}
public void setTotalPaidoffLeave(Long totalPaidoffLeave) {
this.totalPaidoffLeave = totalPaidoffLeave;
}
@Column(name = "status", nullable = false, columnDefinition = "TEXT")
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id", nullable = false)
@ForeignKey(name = "fk_authorities_users")
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
LeaveApp.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- LeaveAppication business object -->
<bean id="leaveBo" class="com.nagra.leave.UserAutenBo.LeaveUserInfoBoImpl">
<property name="leaveuserDao" ref="leaveuserDao" />
</bean>
<!-- LeaveAppication Data Access Object -->
<bean id="leaveuserDao" class="com.nagra.leave.UserAuthe.Dao.LeaveUserinfoDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
次のエラーが表示されます。
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.nagra.leave.User.leaveInfo[com.nagra.leave.EmployeeLeave]