1

我有三个表,我想在休眠 4 中映射它们。我正在使用多对一注释。我不知道如何映射超过 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

请帮我。

4

1 回答 1

0

好吧,这就是我在我的应用程序中所做的。所以这是要走的路。

于 2012-07-28T08:08:46.450 回答