POJO design question (mapping Java Objects to a database)

From: hilz (hilz_at_noway.com)
Date: 07/25/04


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



Relevant Pages

  • POJO design question (mapping Java Objects to a database)
    ... Sorry for posting this again. ... ID (long, primary key) ... publie void setGroup ... Long groupId; //or this?????? ...
    (comp.lang.java.programmer)
  • Re: stored procedure performance
    ... SELECT CAST(COUNT(DISTINCT GroupId) AS FLOAT) / COUNTAS GroupPct ... So we decided to use MSDE. ... the limitation of MSDE is Max. 16 Database and max. 2 GB per ... > Your table has no Primary Key, ...
    (microsoft.public.sqlserver.programming)
  • Re: String Search
    ... GroupID varcharNOT NULL PRIMARY KEY, ... ProjID varcharNOT NULL PRIMARY KEY, ... INNER JOIN UserGroup UG ON U.UserID=UG.UserID ...
    (microsoft.public.sqlserver.programming)