-->
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.  [ 3 posts ] 
Author Message
 Post subject: Relationships between tables-two columns create unique index
PostPosted: Thu Oct 06, 2005 4:41 am 
Newbie

Joined: Tue Oct 04, 2005 6:20 am
Posts: 9
I have a problem with a database that I don't control.

The database was written so that two fields/columns in certain tables identify a unique item.

As an example, consider having a student table and a class participant table. Rather than linking to a student number in the class participant table it links to the first name and surname fields.

Student
    Student number
    First Name
    Surname

Class Participants
    Class ID
    First Name
    Surname


(Please don't get bogged down on why you would do it like this, just accept that it has been done)

What I need to do is create a relationship in the Students.hbm.xml and ClassParticipants.hbm.xml files and I'm not sure how to do this.

The relationship would be one (Students) to many (Class Participants)

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 10:09 am 
Newbie

Joined: Tue Oct 04, 2005 6:20 am
Posts: 9
Would it be possible for me to use a class?

For exemple, if I created a class called person that had a first name and a surname property could I use this in the set?

If so how do I reference it because as far as I can see you can only reference table columns?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 11:32 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can bundle first and last name into a class, for example PersonName, change your objects to use a property of that class instead of the two name properties, and then use property-ref attribute of <many-to-one>. You need the PersonName class because you can't name two properties in property-ref.


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