-->
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: Referential Integrity Mapping
PostPosted: Sat Jan 17, 2004 12:02 am 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Hello,

I am new to Hibernate and for that matter new to Object Relation Database. I have a database model that I would like to refactor so as to add the persistance layer for data access rather than doing direct access.

In this regard I had some basic modelling question.

Since I already have the legacy data with primary keys and foreign keys, I am noting doen a small use case here.

I have two tables, A and B.

Table A
attribute1 PK
attribute2 PK
attribute3 PK

Table B
attribute11 PK
attribute22 PK
attribute3 PK, FK refers attribute3 in tableA

A to B is one to many.


After going through the documentation for hibernate, I find that this design encouraged. Fortunately I have the luxury of changing the design.

Hence I came up with whatever understanding I have of ORM and Hibernate

Define Class A and B

Class A
Long A_id PK
attribute1
attribute2
attribute3

Class B
Long B_id PK
attribute1
attribute2
attribute3

Class B is associated to Class A as many to one. This takes care of the FK integrity.

However, I still need to enforce the unique constraint for the composite attribute1/2/3 in class A and B.

How can I do this. Is there a better way of modelling this.

Any advice will be highly appreciated.

TIA
Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2004 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://forum.hibernate.org/viewtopic.php?t=926855&highlight=dao+process+constraint

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2004 11:56 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Thanks Emmanuel for the link. I think I found what I was looking for at this link

http://forum.hibernate.org/viewtopic.ph ... ght=unique


I think I will stick with the option "1" as I don't want to put business logic to check for duplication or otherwise. I guess I should let that be handled best by the database.

BTW, I have been going through the Hibernate documentation and I have to give kudos to the Hibernate team for coming up with such an extensive documentation, a hard thing to come by in open source.

Thanks
Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 5:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Feel free to update http://www.hibernate.org/95.html :)

_________________
Emmanuel


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.