我得到錯誤: 調用init方法失敗;嵌套異常是org.hibernate.MappingException:實體映射中的重複列:com.messagemanager.domain.User column:id(應該映射爲insert =「false」update =「false」)我收到錯誤:調用init方法失敗;嵌套異常是org.hibernate.MappingException:實體映射中的重複列
有我的實體:
@MappedSuperclass
public abstract class BaseEntity{
@Id
@Column(nullable = false, unique = true, name = "id", insertable = false, updatable = false)
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
@Entity
@Table(name = "User")
public class User extends BaseEntity implements Serializable{
@Column(name = UserFieldsKey.ID, length = 50, nullable = false)
private String name;
@Column(updatable = false, insertable = false)
@Transient
private List<Message> listMessage = new ArrayList<>();
public static class UserFieldsKey{
public static final String NAME = "name";
}
public User() {
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
public List<Message> getListMessage() {
return listMessage;
}
public void setListMessage(List<Message> listMessage) {
this.listMessage = listMessage;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
@Table(name = "Message")
public class Message extends BaseEntity implements Serializable{
@Column(name = MessageFieldsKey.MESSAGE, length = 500, nullable = false)
private String message;
@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="user")
private User user;
@Column(name = "id_user")
private Long id_user;
public Long getId_user() {
return id_user;
}
public void setId_user(Long id_user) {
this.id_user = id_user;
}
public static class MessageFieldsKey{
public static final String MESSAGE = "mes";
}
public String getMessage() {
return message;
}
public User getUser() {
return user;
}
public Message() {
}
public Message(String message, User user) {
this.message = message;
this.user = user;
}
public void setMessage(String message) {
this.message = message;
}
public void setUser(User user) {
this.user = user;
}
}
任何想法?
P.S.非常感謝!
UserFieldsKey.ID的值是什麼? –
@DmitriyS是我嘗試回答的問題? – Eugene
已被封閉。謝謝大家! –