Hibernate问题与映射

时间:2015-08-27 15:39:12

标签: java hibernate

请参阅此代码。我和Branch之间有一对多的关系。我一直收到此错误消息,但无法弄清楚问题是什么。这是一个例外:

    org.hibernate.MappingException: Repeated column in mapping for entity:     com.bank.entity.Branch column: id (should be mapped with insert="false" update="false")

BRANCH CLASS

@Entity
@Table(name = "Branch")
public class Branch extends AbstractPersistable<Long> implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;

@OneToMany(mappedBy = "branch")
private Set<Customer> customers;
}

CUSTOMER CLASS

@Entity
@Table(name = "Customer")
public class Customer extends AbstractPersistable<Long> implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;;

@ManyToOne
@JoinColumn(name = "branchId", nullable = false)
private Branch branch;
}

我尝试在不同的地方插入updateable = false,insertable = false,但不断收到错误。任何建议都值得赞赏。感谢

1 个答案:

答案 0 :(得分:1)

请阅读this

由于您使用的是 AbstractPersistable ,因此无需指定&#34; id &#34;你实体类中的属性。要么不做扩展&#34; AbstractPersistable &#34;或删除&#34; id &#34;来自你的课程。它应该工作。