我使用:NetBeans IDE 6.7.1,GlassFish v2.1,Oracle 10g XE,JAVA 6 SE, JAVA 5 EE。來自實體類[...]的帶註釋元素的@JoinColumns是不完整的
我有一個@ManyToMany註釋的問題:在GlassFish 2.1.1的輸出
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="CUST_RENT_MOVIE", joinColumns={@JoinColumn(name="CUST_ID")}, inverseJoinColumns={@JoinColumn(name="TITLE")})
private Collection<CustRentMovie> rents = new ArrayList<CustRentMovie>();
部分
Exception Description: The @JoinColumns on the annotated element [private java.util.Collection vc.domain.Customer.rents] from the entity class [class vc.domain.Customer] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referenceColumnName elements must be specified in each such @JoinColumn.
javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.1 (Build b31g-fcs (10/19/2009))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
Exception Description: predeploy for PersistenceUnit [vc_pu] failed.
部分腳本創建數據庫:
CREATE table customer
(
cust_id NUMBER(5),
CONSTRAINT cust_pk PRIMARY KEY (cust_id),
...
)
CREATE TABLE movie
(
title VARCHAR2(50) PRIMARY KEY,
...
)
CREATE TABLE cust_rent_movie
(
title VARCHAR2(50),
cust_id NUMBER(5),
rent_date DATE DEFAULT current_date NOT NULL,
return_date DATE,
CONSTRAINT cust_rent_movie_pk PRIMARY KEY (title, cust_id, rent_date),
CONSTRAINT CustRentMovie_movie_fk FOREIGN KEY (title) REFERENCES movie ON DELETE CASCADE,
CONSTRAINT CustRentMovie_cust_fk FOREIGN KEY (cust_id) REFERENCES customer ON DELETE CASCADE
)
客戶類別代碼
@Entity
@Table(name = "customer")
@SequenceGenerator(name="seq", sequenceName="cust_id_seq", allocationSize=1)
public class Customer implements Serializable
{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
@Column(name="CUST_ID")
private int id;
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="CUST_RENT_MOVIE", joinColumns={@JoinColumn(name="CUST_ID")}, inverseJoinColumns={@JoinColumn(name="TITLE")})
private Collection<CustRentMovie> rents = new ArrayList<CustRentMovie>();
public Collection<CustRentMovie> getRents()
{
return rents;
}
public void setRents(Collection<CustRentMovie> rents)
{
this.rents = rents;
}
...
}
錯我的收藏把類型類CustRentMovie而不是電影,所以我改變了
private Collection<CustRentMovie> rents = new ArrayList<CustRentMovie>();
到
private Collection<Movie> movies = new ArrayList<Movie>();
只是可以肯定,你真的要映射的許多'Customer'和'CustRentMovie'之間的多對多關聯(或者'Customer'和'Movie'之間的多對多關聯)? – 2010-08-11 21:35:44
我想映射客戶和電影之間的多對多關聯。 CustRentMovie是連接表。該協會在紅色的日子和返回的日子中具有屬性。由於客戶可能會租用同一部電影,因此我將red_date添加到主鍵。 – IVANNHS 2010-08-12 04:54:09
這就是我的想法。 – 2010-08-13 04:05:57