-->
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.  [ 1 post ] 
Author Message
 Post subject: Question on hibernate mapping
PostPosted: Tue Apr 29, 2008 2:04 pm 
Newbie

Joined: Tue Apr 29, 2008 12:32 pm
Posts: 1
I am relatively new to hibernate but I know MySQL. I feel like the way I am mapping my database tables is inefficient in certain areas. I have been reading link as an example of what I *almost* want.

http://www.hibernate.org/hib_docs/refer ... ional-join

This example uses the following three tables.
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null, addressId bigint not null primary key )
create table Address ( addressId bigint not null primary key )

What if I wanted something similar such as Person, Zip, and State. So I search a zip code in the State_Zip table to find a stateId, and then search for the state name based on stateId, and i store the stateId in the person table for reference.

create table Person( personId int not null primary key, state int not null foreign key references State(stateId))
create table State(stateId int not null primary key, name varchar(30))
create table State_Zip(stateId foreign key references State(stateId), zip int)

This is similar but different than the example as in the example PersonAddress has a Fkey to both Person and Address, but here Person and State_Zip both have a Fkey to State. So the table setup I want doesn't link all the tables together by one linker (PersonAddress) table

I am just wondering if I still would use a Bidirectional associations with joins or if I would have to use some other way to link these tables.

My current walk-around is giving each table a Primary Key and mapping them as many-to-one or one-to-many associations. I feel like since I need to add a PKey to get this to work I am doing something I don't need to be doing. Is there an easier way to map this?


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

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.