gpt4 book ai didi

java - Hibernate - 使用@OneToMany 或@ManyToMany 定位未映射的类 : com. podro.model.Journey.roadWay[com.podro.model.RoadElement]

转载 作者:行者123 更新时间:2023-11-28 23:32:30 25 4
gpt4 key购买 nike

我看到了类似的问题,但答案没有帮助。所以,我得到这个错误:

Use of @OneToMany or @ManyToMany targeting an unmapped class: com.podro.model.Journey.roadWay[com.podro.model.RoadElement]

我正在尝试使用 RoadElements 的对象(它是类 Point 和 Section 的接口(interface))创建 List。还有其他方法吗?据我所知,我想这是为此类创建适当映射并拥有此类元素列表的唯一方法。

@Entity
@Table(name="Journey")
public class Journey {
// Some other fields
@Column(name="road_way")
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
private List<RoadElement> roadWay;
}


@MappedSuperclass
public interface RoadElement {}

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name="Point")
public class Point implements RoadElement{

@Id
@Column(name="id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;

private String name;
@Column(name="time_in_days")
private int timeInDays;
private Rate rating;
}

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name="Section")
public class Section implements RoadElement{

@Id
@Column(name="id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;

@Column(name="section_name" , length=100)
private String sectionName;

@Column(name="time_in_days")
private int timeInDays;

@Column(name="kind_of_transport")
private Locomotion kindOfTransport;

}

感谢您的回答,我将不胜感激!

最佳答案

实体之间的关联。 RoadElement 不是一个实体。它是一个界面。

你可能不会做你想做的事。 Hibernate 需要知道 roadWay 中包含的实体的类型。

因此,RoadElement 应该是一个类,用@Entity 注释,具有在所有道路元素(路段、点等)中唯一标识 RoadElement 的 ID

Section 和 Point 应该从 RoadElement 扩展,并且不应该有自己的 ID,因为它是从 RoadElement 继承的。

关于java - Hibernate - 使用@OneToMany 或@ManyToMany 定位未映射的类 : com. podro.model.Journey.roadWay[com.podro.model.RoadElement],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36955819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com