Hibernate重复映射字段
有时候,使用@ManyToMany@JoinColumn这种形式的表关联会和原本的@Basic@Column造成冲突
代码如下:
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Role.class)
@JoinColumn(name="role_id")
public Role getRole() {
return role;
}
@Basic
@Column(name = "role_id", nullable = true)
public Integer getRoleId() {
return roleId;
}解决方法
在@JoinColumn中将属性设置只读
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Role.class)
@JoinColumn(name="role_id", insertable = false, updatable = false)
public Role getRole() {
return role;
} 相关推荐
LaputaSpring 2012-02-09
laj0 2009-06-01
记录学习备忘人生 2012-12-12
hualicc 2011-11-17
SwingGUI 2011-04-08
VincentDrW 2008-04-02