我是 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]
我有四个实体,称为 - Customer - Item - Order - OrderId
它们都与一对多和多对一的关系相关联。
这里有一些代码
@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>