-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: design question
PostPosted: Thu Feb 19, 2009 11:55 am 
Newbie

Joined: Thu Feb 19, 2009 11:16 am
Posts: 3
Location: Denver
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3

Mapping documents: annotations

Code between sessionFactory.openSession() and session.close(): none yet

Full stack trace of any exception that occurs: none yet

mySQL 5.0.67:

The generated SQL (show_sql=true): none yet

Debug level Hibernate log excerpt:none yet

Hello, I am a relative newbie to Hibernate and am unable to find an answer to a question. I am not sure if I have a bad design, or expectations but I would greatly appreciate any advice you can offer for a new project:

I have an address table that I want to share with employee, customer, company, and possibly other entities that have an address. Is it possible to have a onetoone between each of these and the address? As I understand it, a lookup table would only link address and one other type (employee for example). That works if I want to find the address of an employee, but not if I want to go the other direction - asking an address who owns it. Is this a valid approach, or should I have a seperate address table for each type such as employeeAddress, customerAddress tables, etc?

Thank you very much for your time and patience.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 12:18 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I think a good approach would be to use address as embeddable so that it is stored within the owner's table. Customer and Employee could have a superclass Person, which has the address, so that it is not redundant.

(Having a superclass for employee, customer, company, and possibly other entities could also be a solution to get a bidirectional one to one between address and your superclass, but better use embeddable)

If you use xml look here, for annotations here.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 3:56 pm 
Newbie

Joined: Thu Feb 19, 2009 11:16 am
Posts: 3
Location: Denver
Thank you for the advice. I went and looked at Embeddable and I am not sure I follow it 100%. When an Employee has an embeddable Address, does that Address get persisted to the employee or address table? And does that allow me to search for Employee based upon Address values?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 7:01 am 
Newbie

Joined: Mon Feb 02, 2009 4:55 am
Posts: 5
sonoerin wrote:
Thank you for the advice. I went and looked at Embeddable and I am not sure I follow it 100%. When an Employee has an embeddable Address, does that Address get persisted to the employee or address table? And does that allow me to search for Employee based upon Address values?


Embedded objects do not have an id. so they will not have a separate table of their own. You can search based an employee based on the Address using Address.xxx just like you access variables of other objects


Top
 Profile  
 
 Post subject: continuing problem
PostPosted: Wed Mar 18, 2009 10:06 pm 
Newbie

Joined: Thu Feb 19, 2009 11:16 am
Posts: 3
Location: Denver
Hello -

thank you for the past help, but I wasn't comfortable with the embedded solution because it seemed like if I wanted to find an employee or office based upon phone number, I would have to load up both tables and then search for the results. But it is entirely possible that I don't quite understand embeddable fully.

After talking with a dba friend, he suggested that the following might work very efficiently:

EMPLOYEE
int employee_id (pk)

OFFICE
int office_id (pk)

PHONE
int phone_id (pk)
int tableRefId
int phoneRefId

ADDRESS
int address_id (pk)
int tableRefId
int addressRefId

TABLEREFID
int tableRefId (pk)
String descrip (contractor, employee, manager)

PHONEREF
int phoneRefId (pk)
String desc (cell, office, home)

ADDRESSREF
int addressRefId (pk)
String descrip (employee, supplier)

However, Hibernate doesn't seem to lend itself to this. I think the db part is fine and I can see how I could have one address table to support multiple users of addresses (office, employee, supplier, etc). Is this something that I will have to use HQL for, or will annotation mapping support it?

Thank you for your time and patience, I really do appreciate it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.