-->
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: Rel 1-to-many -how hibernate determine columns in relatation
PostPosted: Fri Jun 30, 2006 3:50 am 
Newbie

Joined: Fri Jun 30, 2006 3:17 am
Posts: 1
Hello,

I am using a one to many relation between two tables - users and cars, as every user can have more than one car.
The user table has fields: (UserID, username, password, email...), the cars table has fields (CarID, CarName, CarOwner, dateOfProduction). I have the folloding mapping classes:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="User" table="Users">
<id name="UserID">
<generator class="sequence">
<param name="sequence">UserID_SEQ</param>
</generator>
</id>

<property name="Username"/>
<property name="Password"/>
<property name="FirstName"/>
<property name="LastName"/>
<property name="Birthdate"/>
<property name="City"/>
<property name="Sex"/>

<bag name="UsersCars" table="Cars">
<key column="CarOwner"/>
<one-to-many class="Car"/>
</bag>

</class>
</hibernate-mapping>

-------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Car" table="Cars">
<id name="CarID">
<generator class="sequence">
<param name="sequence">CarID_SEQ</param>
</generator>
</id>

<many-to-one name="CarOwner" class="User" column="CarOwner"/>

<property name="CarName"/>
<property name="DateOfProduction"/>

</class>
</hibernate-mapping>

There is a unique index for column username.
I have the followind question:

How does the hibernate understands which columns to use to make the ralation between the two tables, as in thiese mapping files I am writing only the foreign key column - CarOwner - in both the bag definition and the many-to-one-name.

I mean how does the hibernate understands that the relation between the two tables is between columns Users.Username and Cars.Owner?

Thanks,
Alex


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.