在hibernate注释中映射多于2个表

时间:2012-07-28 07:49:44

标签: java hibernate java-ee orm hibernate-mapping

我有三个表,我想在hibernate 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

请帮帮我。

1 个答案:

答案 0 :(得分:0)

这就是我在我的应用程序中完成它的方式。所以这是要走的路。