Java org.hibernate.MappingException:无法确定抽象类表的类型
我试图创建一个抽象类,作为更具体案例的蓝图。 我试图实现的是,我可以在其他容器中存储物品和容器 存储单元Java org.hibernate.MappingException:无法确定抽象类表的类型,java,spring,hibernate,orm,Java,Spring,Hibernate,Orm,我试图创建一个抽象类,作为更具体案例的蓝图。 我试图实现的是,我可以在其他容器中存储物品和容器 存储单元 @Entity public abstract class StorageUnit { @Id @GeneratedValue(strategy=GenerationType.AUTO) private double id; // Dimensions private double width, height, length; private
@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;
}
}
但是,我得到了以下信息:
原因:org.hibernate.MappingException:无法确定类型
for:com.warehousing.storage.Item,在表中:存储单位,for
列:[org.hibernate.mapping.Column(项)]
有没有简单的解决办法?我尝试过使用基于场地/财产的访问,但我觉得我的问题比这更复杂。谢谢
StorageUnit
应该是@MappedSuperclass
@XtremeBaumer确实是这个问题。谢谢大家!StorageUnit
应该是@MappedSuperclass
@XtremeBaumer确实是这个问题。非常感谢。
@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();
}
}