POJO design question (mapping Java Objects to a database)
From: hilz (hilz_at_noway.com)
Date: 07/25/04
- Next message: Luca Paganelli: "Re: Trying to create a database in a MS Access DB via JDBC drivers"
- Previous message: Liz: "Re: Trying to create a database in a MS Access DB via JDBC drivers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 25 Jul 2004 05:45:56 GMT
Hi all:
If i have a two tables in an existing database, with a relation one-to-many
(one GROUP to many ITEMs)
table GROUP has columns:
ID (long, primary key)
NAME (string)
table ITEM has columns:
ID (long, primary key)
GROUP_ID (long, foreign key)
NAME (string)
ITEM_COST (double)
I want to design POJO classes "Group" and "Item" that map to these tables
my question is about the "Item" class:
should the "Item" class contain a field "groupId" of type Long, with its
getter and setter, or just a reference to a Group object, or both?
for example:
publie class Item{
.
.
Group group; //this?????
public Group getGroup(){return group;}
publie void setGroup(Group group){this.group = group;}
.
.
Long groupId; //or this??????
public Long getGroupId(){return groupId;}
public void setGroupId(Long groupId){this.groupId = groupId;}
.
.
// or both??????
}
thanks
hilz
- Next message: Luca Paganelli: "Re: Trying to create a database in a MS Access DB via JDBC drivers"
- Previous message: Liz: "Re: Trying to create a database in a MS Access DB via JDBC drivers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|