0
我想使用@JoinColumn作为@Id使用JPA,我得到SerializationExceptions,“无法序列化”。JPA - @JoinColumn是否也可以是@Id? SerializationException发生
UserRole.java:
@Entity
@Table(name = "authorities")
public class UserRole implements Serializable {
@Column(name = "authority")
private String role;
@Id
@ManyToOne
@JoinColumn(name = "username")
private User owner;
...
}
User.java:
@Entity
@Table(name = "users")
public class User implements Serializable {
@Id
@GeneratedValue
protected Long id;
@Column(name = "username")
protected String email;
@OneToMany(mappedBy = "owner", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
protected Set<UserRole> roles = new HashSet<UserRole>();
....
}
“用户名” 设置为我的用户表中的唯一索引,但不能作为主键。
有什么办法可以让“username”充当UserRole的ID吗?我不想在UserRole中引入数字键。我完全在这里失去了阴谋吗?
我在引擎盖下使用MySQL和Hibernate。
当然,你是对的。而我是个白痴! – Shivago 2010-05-13 16:46:24