【发布时间】:2013-06-03 11:12:15
【问题描述】:
我是 JPA 领域的新手,在这里我遇到了这个问题。
我尝试的是通过使用从带注释的实体中导出架构
new SchemaExport(config).create(true, true);
它给了我这个错误
Exception in thread "main" org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.hidvd.entities.Customer.orders[com.hidvd.entities.Order]
我有四个实体称为 - 顾客 - 物品 - 命令 - 订单编号
它们都以一对多和多对一的关系联系在一起。
这里有一些代码
@Entity
public class Customer {
@Id
@Column(name = "cust_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int custid;
@Column(length = 50, nullable = false, unique = true)
private String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer")
private List<Order> orders = new ArrayList<Order>();
}
@Entity(name = "item")
public class Item implements Serializable{
public Item() {
super();
}
@Id
@Basic(optional = false)
@Column(name = "item_id", unique = true, nullable = false)
private int itemid;
private String title;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "item")
private List<Order> orders = new ArrayList<Order>();
@Entity(name = "order")
@AssociationOverrides({
@AssociationOverride(name = "customer",
joinColumns = @JoinColumn(name = "cust_id")),
@AssociationOverride(name = "item",
joinColumns = @JoinColumn(name = "item_id")) })
public class Order implements Serializable {
private OrderId pk = new OrderId();
private Calendar orderedDate;
@Embeddable
public class OrderId implements Serializable{
@ManyToOne
private Customer customer;
@ManyToOne
private Item item;
任何建议将不胜感激。在此先感谢:)
- 这是 persistence.xml 文件
<persistence-unit name="hidvddb"> <jta-data-source>java:/MySQLDS</jta-data-source> <properties> <property name="showSql" value="true"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> </properties> </persistence-unit> </persistence>
【问题讨论】:
-
您能在此处发布您的 persistence.xml 文件吗?似乎休眠没有拿起你的实体
-
@ufasoli 谢谢我上传了。
-
您忘记在 persistence.xml 文件中列出您的实体。