persistence@glassfish.java.net

Re: Composition, inheritance or queries: best practice

From: Greg Ederer <greg_at_ergonosis.com>
Date: Tue, 07 Nov 2006 09:54:28 -0800
Hi Craig,

Thanks for the advice.  This is essentially what I'm doing.  I have created classes called CustomerNature, VendorNature, AuthorNature, and so on.  These classes extend an AppUserNature base class.  My AppUser class has methods addNature(AppUserNature a), getNature(String className) and hasNature(String className).

(This is probably an established design pattern.  But, I don't know what it's called.  Anyone know?)

Navigating the resulting web of objects can be a bit cumbersome.  But, this may just be the best way.

Again, thanks.

Cheers,

Greg

Craig L Russell wrote:
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@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@sun.com

P.S. A good JDO? O, Gasp!




--
| E R G O N O S I S
| Greg Ederer
| Lead Developer
| greg@ergonosis.com
| 360.379.1157
| 
| OpenDocument - OK
|