JPA MappedSuperClass

时间:2015-03-17 01:09:58

标签: hibernate jpa

我在我的hibernate项目中使用@MappedSuperclass

@MappedSuperclass
public abstract class AbstractHotel extends AbstractData {
    protected String id;
    protected String name;
    protected String type;
    ....
}

@Entity
@Table(name = "T_HOTEL")
public class Hotel extends AbstractHotel {
    @AttributeOverride(name = "id", column = @Column(name = "hotel_id"))
    protected String id;

    @AttributeOverride(name = "name", column = @Column(name = "hotel_name"))
    protected String name;

    @AttributeOverride(name = "type", column = @Column(name = "hotel_type"))
    protected String type;

    ...
}

如图所示,我希望列可以在子类中被覆盖,但是我收到错误:

org.hibernate.MappingException: Duplicate property mapping of id found in cn.test.Hotel

有可能解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您不应该在子类中再次定义字段:请查看:https://stackoverflow.com/a/5258090/286588