persistence@glassfish.java.net

Re: Composition, inheritance or queries: best practice

From: Craig L Russell <Craig.Russell_at_Sun.COM>
Date: Tue, 07 Nov 2006 09:39:26 -0800

Hi Greg,

Consider domain classes User, Customer, Vendor. User has a 1:0..1
relationship with Customer and Vendor (a Customer must have a User
but a User might not have a Customer). You can navigate from Customer
and Vendor to the corresponding User instance. You can navigate from
User to Customer and Vendor (might be null in the object model).

Represent each of User, Customer, and Vendor with its own table.
Customer and Vendor have a non-null foreign key to User table.

Craig

On Nov 7, 2006, at 8:54 AM, Greg Ederer wrote:

> Hi,
>
> I am building a system that has various kinds of users. All users
> have first and last names, a username and a password. Customer
> users have a shopping cart and orders; vendor users have products
> and commissions, author users have articles; et cetera. Any user
> can be more than one kind of user; e.g., an author can also be a
> customer and a vendor all at the same time. What is the best way
> to architect this using JPA?
>
> Thanks in advance for any suggestions.
>
> Cheers,
>
> Greg
> --
> | E R G O N O S I S
> | Greg Ederer
> | Lead Developer
> | greg_at_ergonosis.com
> | 360.379.1157
> |
> | OpenDocument - OK
> |
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell_at_sun.com
P.S. A good JDO? O, Gasp!