2012-07-02 69 views
0

Possible Duplicate:
Hibernate problem - 「Use of @OneToMany or @ManyToMany targeting an unmapped class」一個一對多的關係休眠錯誤

我在春天G642.44各級休眠project.But我在項目中添加一個一對多我有錯誤

User.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] 

回答

0

你的會話工廠應該列出由Hibernate映射的所有類。鑑於錯誤,你只是忘了添加com.nagra.leave.EmployeeLeave到這個列表!