我在Spring + Hibernate 4.1应用程序中创建oneToMany关系时遇到了一些问题这是我的实体类.每个USER_ROLE记录都有FK到USER记录.我在互联网上找不到任何有用的东西.
@Entity
@Table( name = "USERS" )
public class User {
long id;
String login;
String password;
String name;
String surname;
GregorianCalendar birthDate;
String email;
GregorianCalendar joinDate;
String randomKey;
List<UserRole> userRoles = new ArrayList<UserRole>();
public User(){ } //JavaBean Hibernate requirement
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy = "increment")
@Column(name="USER_ID", unique=true, nullable=false)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
...
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
public List<UserRole> getUserRoles() {
return …Run Code Online (Sandbox Code Playgroud)