File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Table Design Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Table Design Question" Watch "Table Design Question" New topic

Table Design Question

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

This may not be an ORM specific question but since I am asking in the context of "Java Persistance with Hibernate" I think this forum is as good as any...

In "JP w/H" the authors talk about compositions and they give an example of a USER table with colums for ADDRESS in the USER table. And then using a composition mapping to map the ADDRESS data to a seperate Address class that is a property of the User class. Address is a value type and User is an entity. (JP w/H p. 184,185).

While I understand the concept, other than legacy databases, I don't think I would ever impement the association as such. I would want a seperate table with it's own identity for Address and use a ManyToOne type of association. Am I naive to assume this is preferred?

GenRocket - Experts at Building Test Data
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Yes, you are correct in that in the real world of today you would design Address as having its own table, and that for that example Legacy databases might have address info in the User table.

And it is being used just as an example to should how to map/annotate a Composition.

Later on you will probably see a better example with a MonetaryAmount object.

So just look at it that way and say oh I see @Embeddable and @Embedded or <component....>

I say this everytime when teaching the Hibernate classes.

[ January 28, 2007: Message edited by: Mark Spritzler ]

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Thanks Mark. I assumed as much. I just wanted to make sure I wasn't missing something. I'm sure as I continue through the book I'll have some more of these types of question.
I agree. Here's the link:
subject: Table Design Question
It's not a secret anymore!