create table Users ( LogonID VARCHAR(255) not null, EmailAddress VARCHAR(255), LastLogon DATE, PassWord VARCHAR(255), Name VARCHAR(255), PRimary key (LogonID) );
create table Address2 ( ID VARCHAR(255) not null, City VARCHAR(255), State VARCHAR(255), Zip VARCHAR(255), primary key (ID) ); create table Contacts ( ID BIGINT not null, EmailAddress VARCHAR(255), Name VARCHAR(255), User_ID VARCHAR(255), primary key (ID) ); alter table Contacts add constraint FKE207C4735A7381EF foreign key (User_ID) references Users; create index IXE207C4735A7381EF on Contacts (User_ID);
其中Address2,Contacts,Users相当于实体bean,实现对数据表的映射。由于表Users和Contacts存在one-to-many关系,所以在Users.java的实现中将Contacts也作为一个对象属性。 private java.util.Set _contactsSet; /** * Return the value associated with the column: ContactsSet */ public java.util.Set getContactsSet () { return this._contactsSet; }
/** * Set the value related to the column: ContactsSet * @param _contactsSet the ContactsSet value */ public void setContactsSet (java.util.Set _contactsSet) { this._contactsSet = _contactsSet; }