-->
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.  [ 4 posts ] 
Author Message
 Post subject: is it possible to map this "creative" database sch
PostPosted: Thu May 12, 2005 8:05 am 
Newbie

Joined: Thu May 12, 2005 7:42 am
Posts: 3
I am currently evalutating the possibility of using hibernate bridging between an old database schema and a newly developed java object model and I'm wondering if the following can be done in hibernate:

There is a table PERSON, holding simple person properties. To keep the column count manageable someone decided to create a new table PERSON_EXTRA that has a one-to-one relationship with person. The primary key in PERSON_EXTRA is PERSON_ID and also a foreign key refering to the PERSON table.

Now it happens to be so that some properties in PERSON_EXTRA groups logically into a class holding employment information in the java object model (Employment), and some properties groups logically into information about the current landlord of the person (Landlord).

I have created a one-to-one association between User <-> Employment and User <-> Landlord using the method decscribed in "One-to-one associations" / "Using a primary key association" on page 223 in "Hibernate in action" and it works great for reading data from the database.

When saving new data to the database however the insert of the Landlord data fails as a second insert with the same primary key into PERSON_EXTRA violates the uniqueness constraint of the primary key.

Is there a way of persuading hibernate to save both the new Landlord and Employment objects in the same PERSON_EXTRA row? Is there another smart way of achieving the same thing?

I hope someone has a solution to this problem, as hibernate seems great in so may ways and I'd love to use it, but changing the database schema is not an option for us unfortunately :/


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 8:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about this:
http://www.hibernate.org/hib_docs/v3/re ... ation-join
?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 8:44 am 
Newbie

Joined: Thu May 12, 2005 7:42 am
Posts: 3
Excellent. Embedding <component>s in the <join> does the trick. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 9:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you're welcome

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.