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

时间:2022-02-18 23:34:32

I have two classes: Furniture and Painting. Those are extending Item.

我有两个类:家具和绘画。那些正在扩展项目。

Item has the following code:

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);
    }

Painting has the following code:

绘画具有以下代码:

@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 has the following code:

家具有以下代码:

@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;
    }

Before, I tried some code persisting the Item objects. That worked fine. Now I'm trying to persist a Painting-object, persisting it through an Entity Manager. I get the following error:

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

Object: auction.domain.Furniture@5d3468fd is not a known entity type.

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

It seems like I forgot something or did something wrong, probably in the Painting-class. What could it be?

似乎我忘记了某些事情或做错了什么,可能是在绘画课上。会是什么呢?

1 个解决方案

#1


0  

I forgot to update my Persistence Unit. After adding the Furniture and Painting classes, the information got in to the database. Above code is correct.

我忘了更新我的持久性单元。添加“家具”和“绘画”类后,信息将进入数据库。以上代码是正确的。

#1


0  

I forgot to update my Persistence Unit. After adding the Furniture and Painting classes, the information got in to the database. Above code is correct.

我忘了更新我的持久性单元。添加“家具”和“绘画”类后,信息将进入数据库。以上代码是正确的。