class design vs. db design

Discussion in 'Java' started by John_Woo, Dec 19, 2006.

  1. John_Woo

    John_Woo Guest

    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
     
    John_Woo, Dec 19, 2006
    #1
    1. Advertising

  2. John_Woo

    Oliver Wong Guest

    "John_Woo" <> wrote in message
    news:...
    > 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
     
    Oliver Wong, Dec 19, 2006
    #2
    1. Advertising

  3. John_Woo

    John_Woo Guest


    > > 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
     
    John_Woo, Dec 19, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,801
    Thomas Weidenfeller
    Oct 12, 2005
  2. christopher diggins
    Replies:
    16
    Views:
    761
    Pete Becker
    May 4, 2005
  3. Joseph Turian
    Replies:
    5
    Views:
    603
  4. Bartholomew Simpson

    class design/ design pattern question

    Bartholomew Simpson, Jun 12, 2007, in forum: C++
    Replies:
    2
    Views:
    453
    Daniel T.
    Jun 12, 2007
  5. Replies:
    8
    Views:
    414
    Greg Herlihy
    Jun 28, 2008
Loading...

Share This Page