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?