org.hibernate.MappingException: не удалось определить тип для таблицы абстрактных классов - PullRequest
1 голос
/ 10 февраля 2020

Я пытаюсь создать абстрактный класс, который используется в качестве схемы для более конкретных c случаев. Я пытаюсь добиться того, чтобы я мог хранить предметы и контейнеры в других контейнерах.

StorageUnit

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

Item

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

Однако я получаю следующее:

Причина: org.hibernate.MappingException: Не удалось определить тип для: com .warehousing.storage.Item, в таблице: storage_unit, для столбцов: [org.hibernate.mapping.Column (item)]

Есть ли простое решение для этого? Я попытался поиграть с доступом на основе полей / свойств, но чувствую, что моя проблема сложнее. Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...