1
我有三張表,我想將它們映射到休眠4. 我使用多對一的註釋。我不知道如何映射2個以上的表格。在休眠註釋中映射2個以上的表格
1. Stuff
CREATE TABLE TBLSTUFF (
STUFF_ID NUMBER NOT NULL,
STUFF_DESCRIPTION VARCHAR2(10),
MUNIT VARCHAR2(10),
ORDERPOINT NUMBER,
STOCK NUMBER,
CONSTRAINT PK_TBLSTUFF
PRIMARY KEY (STUFF_ID)
);
2. STUFFRECEPTION
CREATE TABLE TBLSTUFFRECEPTION (
STUFF_ID NUMBER,
PROVIDER_ID NUMBER,
RECEPTIONDATE DATE,
QUANTITY NUMBER,
RECEPTION_ID NUMBER NOT NULL,
CONSTRAINT PK_TBLSTUFFRECEPTION
PRIMARY KEY (RECEPTION_ID)
);
ALTER TABLE TBLSTUFFRECEPTION ADD CONSTRAINT FK_STUFF
FOREIGN KEY (STUFF_ID)
REFERENCES TBLSTUFF (STUFF_ID);
ALTER TABLE TBLSTUFFRECEPTION ADD CONSTRAINT FK_PROVIDER
FOREIGN KEY (PROVIDER_ID)
REFERENCES TBLPROVIDER (PROVIDER_ID);
3.provider
CREATE TABLE TBLPROVIDER (
PROVIDER_ID NUMBER NOT NULL,
PROVIDER_NAME VARCHAR2(10),
PROVIDER_ADDRESS VARCHAR2(10),
PROVIDER_TELL VARCHAR2(11),
CONSTRAINT PK_TBLPROVIDER
PRIMARY KEY (PROVIDER_ID)
);
在Stuffreception.java中,應該怎麼寫多對一的註釋? 這是真的嗎?
@Entity
@Table(name="TBLSTUFFRECEPTION")
public class Stuffreception {
@Id
@Column(name="RECEPTION_ID")
private int recep_id;
@Column(name="QUANTITY")
private int quantity;
@Column(name="RECEPTIONDATE")
private Date recep_date;
@ManyToOne
@JoinColumn(name="PROVIDER_ID")
private Provider provider;
@ManyToOne
@JoinColumn(name="STUFF_ID")
private Stuff stuff;
public Stuffreception(int recep_id, int quantity, Date recep_date) {
super();
this.recep_id = recep_id;
this.quantity = quantity;
this.recep_date = recep_date;
}
//getter and setter method
請幫幫我。
你是否面臨任何錯誤?這似乎很好。 – SiB 2012-07-28 08:04:47
@BharatSinha,我沒有錯誤,我只知道它是真的。 – samira 2012-07-28 08:07:23
這個實現很好。 – SiB 2012-07-28 08:12:00