有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java组织。冬眠MappingException:无法确定抽象类表的类型

我试图创建一个抽象类,作为更具体案例的蓝图。 我试图实现的是,我可以在其他容器中存储物品和容器

存储单元

@Entity
public abstract class StorageUnit {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private double id;
    // Dimensions
    private double width, height, length;
    private double weight;
    // Properties
    private double value;

    public StorageUnit() {

    }

    public double getId() {
        return id;
    }
    public void setId(double id) {
        this.id = id;
    }
    public double getWidth() {
        return width;
    }
    public void setWidth(double width) {
        this.width = width;
    }
    public double getHeight() {
        return height;
    }
    public void setHeight(double height) {
        this.height = height;
    }
    public double getLength() {
        return length;
    }
    public void setLength(double length) {
        this.length = length;
    }

    public abstract double getWeight();
    public abstract double getValue();

}

它用于以下类别:

容器

@Entity
public class Container extends StorageUnit {

    @OneToMany
    List<StorageUnit> contents;

    public Container() {
        super();
        contents = new ArrayList<>();
    }

    public List<StorageUnit> getContents() {
        return contents;
    }

    public void addContent(StorageUnit content) {
        contents.add(content);
    }

    @Override
    public double getWeight() {
        Iterator<StorageUnit> iterator = contents.iterator();
        double weight = 0;
        while (iterator.hasNext()) {
            weight += iterator.next().getWeight();
        }
        return weight;
    }

    @Override
    public double getValue() {
        Iterator<StorageUnit> iterator = contents.iterator();
        double value = 0;
        while (iterator.hasNext()) {
            value += iterator.next().getValue();
        }
        return value;
    }
}

项目

@Entity
public class Item extends StorageUnit {

    private String description;

    public Item() {
        super();
    }

    public Item(String description) {
        super();
        this.description = description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public double getWeight() {
        return this.getWeight();
    }

    @Override
    public double getValue() {
        return this.getValue();
    }   
}

但是,我得到了以下信息:

Caused by: org.hibernate.MappingException: Could not determine type for: com.warehousing.storage.Item, at table: storage_unit, for columns: [org.hibernate.mapping.Column(item)]

有没有简单的解决办法?我尝试过使用基于场地/财产的访问,但我觉得我的问题比这更复杂。谢谢


共 (0) 个答案