1

我有两个类映射 OneToMany、ManyToOne,但我得到了异常:

org.hibernate.AnnotationException:mappedBy 引用了一个未知的目标实体属性:entity_package.UserEntity.ownedTickets 中的 entity_package.TicketEntity.ownerEntity

这是代码:

公共类 UserEntity 实现 Serializable {

@OneToMany(mappedBy="ownerEntity")
public List<TicketEntity> getOwnedTickets() {
    return tickets;
}
public void setOwnedTickets(List<TicketEntity> tickets) {
    this.tickets = tickets;
}

和 ...

公共类 TicketEntity 实现 Serializable {

private UserEntity ownerEntity;

@ManyToOne
@JoinColumn(name="owner_id")
public UserEntity getOwner() {
    return ownerEntity;
}
public void setOwner(UserEntity owner) {
    this.ownerEntity = owner;
}

怎么了 ?

4

1 回答 1

4

属性名称owner由带注释的 getter 定义。采用:

@OneToMany(mappedBy="owner")
public List<TicketEntity> getOwnedTickets() {
于 2012-04-19T08:35:55.233 回答