扩展对象不在数据库中持久化

时间:2013-01-08 18:07:39

标签: java database inheritance persistence entity

我有两个课程:FurniturePainting。这些正在扩展Item

项目具有以下代码:

@Entity
public class Item implements Comparable, Serializable {

    @Id @GeneratedValue(strategy= GenerationType.AUTO)
    private Long id;
    @ManyToOne 
    private User seller;
    @Embedded
    @AttributeOverrides({
     @AttributeOverride(name = "description",
        column = @Column(name = "c_description"))})
    private Category category;
    private String description;

    public Item() {
    }

    public Item(User seller, Category category, String description) {
        this.seller = seller;
        this.category = category;
        this.description = description;
        this.seller.addItem(this);
    }

绘画具有以下代码:

@Entity
public class Painting extends Item {

    private String title;
    private String painter;

    public Painting() {

    }

    public Painting(String title, String painter, User seller, Category category, String description) {
        super(seller, category, description);
        this.title = title;
        this.painter = painter;
    }

Furniture具有以下代码:

@Entity
public class Furniture extends Item {

    private String material;

    public Furniture() {

    }

    public Furniture(String material, User seller, Category category, String description) {
        super(seller, category, description);
        this.material = material;
    }

之前,我尝试了一些持久化Item对象的代码。这工作得很好。 现在我试图坚持一个Painting - 对象,通过实体管理器持久化它。 我收到以下错误:

  

对象:auction.domain.Furniture@5d3468fd不是已知的实体类型。

似乎我忘记了某些事情或做错了什么,可能是在Painting - 班级。它可能是什么?

1 个答案:

答案 0 :(得分:0)

我忘了更新我的持久单元。添加FurniturePainting类后,信息将进入数据库。上面的代码是正确的。