f



class design vs. db design

Hi,

if I want to reflect a 1:1 relationship for user:account, the design
model may be:

for class:
A.    User
    -------------
   int user_id;
  int account_id;

B.  User
     ------------
    int user_id;
    Account account;

for db:
C. User (user_id int); Account(account_id int, user_id int)

D. User (user_id int, account_id int); Account (account_id int)

Questions:
1. How to compare A vs. B in terms of OO design, JDO (java data object)

2. How to compare A vs. B in terms of db schema (with foreign key
constraint)

3. C vs. D, which is better? should create user first or account first?

---
Thanks
John
Toronto

0
john_woo (82)
12/19/2006 12:32:03 PM
comp.lang.java.programmer 52711 articles. 1 followers. Post Follow

2 Replies
369 Views

Similar Articles

[PageSpeed] 16

"John_Woo" <john_woo@canada.com> wrote in message 
news:1166531523.393419.207410@79g2000cws.googlegroups.com...
> Hi,
>
> if I want to reflect a 1:1 relationship for user:account, the design
> model may be:
>
> for class:
> A.    User
>    -------------
>   int user_id;
>  int account_id;
>
> B.  User
>     ------------
>    int user_id;
>    Account account;
>
> for db:
> C. User (user_id int); Account(account_id int, user_id int)
>
> D. User (user_id int, account_id int); Account (account_id int)
>
> Questions:
> 1. How to compare A vs. B in terms of OO design, JDO (java data object)

    I like B better. It looks like less work to get the account from the 
user.

>
> 2. How to compare A vs. B in terms of db schema (with foreign key
> constraint)

    I suppose A would be slightly less work to implement a ORM for, but you 
could just download an ORM like Hibernate to do the work for you, so I'd 
still stick with B.

>
> 3. C vs. D, which is better? should create user first or account first?

    If the relation is 1:1, why not stick it all in one big table?

    - Oliver 


0
owong (6178)
12/19/2006 6:46:04 PM
> > for db:
> > C. User (user_id int); Account(account_id int, user_id int)
> >
> > D. User (user_id int, account_id int); Account (account_id int)
> >
> > 3. C vs. D, which is better? should create user first or account first?
>
>     If the relation is 1:1, why not stick it all in one big table?
>
Good point, thanks,  Oliver.

but both these two tables may extend, like USER may have 10+ fields,
same as Account table.
if they have to be separated, I'm still looking for tips on selection
of model C, D 

John

0
john_woo (82)
12/19/2006 8:27:02 PM
Reply: