【发布时间】:2016-12-10 16:49:12
【问题描述】:
我正在尝试将用户列表映射到位置对象,但出现映射异常。这是因为 List 对象不被数据库识别?或者为什么我会得到这个异常?
这是我的用户类:
@Entity
@Table(name = "users")
public class NewUser extends BaseEntity{
private String login;
private String fullName;
private Location location;
private Department department;
private Role role;
private Long days;
private String team;
private Long managerId;
private String hiredDate;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public Location getLocation() {
return location;
}
@ManyToOne(targetEntity = Location.class)
@JoinTable(name = "location")
public void setLocation(Location location) {
this.location = location;
}
public Department getDepartment() {
return department;
}
@ManyToOne(targetEntity = Department.class)
public void setDepartment(Department department) {
this.department = department;
}
public Role getRole() {
return role;
}
@ManyToOne(targetEntity = Role.class)
@JoinTable(name = "role")
public void setRole(Role role) {
this.role = role;
}
和位置类:
@Entity
@Table(name = "location")
public class Location extends BaseEntity{
private List<NewUser> users;
public List<NewUser> getUsers() {
return users;
}
@OneToMany(targetEntity = NewUser.class, mappedBy = "location")
@JoinTable(name = "users")
public void setUsers(List<NewUser> users) {
this.users = users;
}
}
基础实体:
@MappedSuperclass
public abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
错误是:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: location, for columns: [org.hibernate.mapping.Column(users)]
如何使用hibernate注解有效地进行关系映射?
【问题讨论】: