Hibernate Books

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: Regarding the bid.hbm.xml in caveatemptor 0.95
PostPosted: Wed Sep 15, 2004 11:32 am 
Newbie

Joined: Mon Aug 16, 2004 2:00 pm
Posts: 7
In the bid.hbm.xml file I find that there is a many-to-one association from a Bid to User. But column BIDDER_ID in the bid table is a foreign key reference to the primary key of user table right ? But I do not find a BIDDER_ID as part of the user table ... How does this work ?

<!-- The other side of this bidirectional one-to-many association to user. -->
<many-to-one
name="bidder"
class="User"
column="BIDDER_ID"
update="false"
cascade="none"
not-null="true"
outer-join="true"
access="org.hibernate.auction.persistence.DirectSetAccessor"
foreign-key="FK2_BIDDER_ID"/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 11:34 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The BIDDER_ID is on the BID table, of course.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 11:58 am 
Newbie

Joined: Mon Aug 16, 2004 2:00 pm
Posts: 7
christian wrote:
The BIDDER_ID is on the BID table, of course.


Thanks ! So BIDDER_ID is a foreign key referencing the primary key of the User table. In the example below,

<class
name="Bid"
table="BID">
...
<many-to-one
name="item"
column="ITEM_ID"
class="Item"
not-null="true"/>
</class>

In page 108 of hibernate in action it is said
"We have explicitly specified the class, Item, that the association refers to. This specification is usually optional, since Hibernate can determine this using reflection."

So in the above case if ITEM_ID alone is specified and not the class Item, then ITEM_ID has the match to map the primary key name on the Item table so that refelection can be used right ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 12:02 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't fully understand the question, but reflection only be used on *-to-one associations and other single-valued properites. With JDK 1.5, Hibernate might soon be able to detect the correct type (and even association style) for collections. This is not related to anything with foreign keys...

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 12:07 pm 
Newbie

Joined: Mon Aug 16, 2004 2:00 pm
Posts: 7
[quote="svpooni70"]

"So in the above case if ITEM_ID alone is specified and not the class Item, then ITEM_ID has the match to map the primary key name on the Item table so that refelection can be used right ?"

should read as

"So in the above case if ITEM_ID alone is specified and not the class "Item", then ITEM_ID has to match the primary key name on the Item table so that hibernate can determine the class by reflection right ?"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 12:27 pm 
Newbie

Joined: Mon Aug 16, 2004 2:00 pm
Posts: 7
To be precise, the question I had was in the many-to-one association definition below

<many-to-one
name="propertyName"
column="column_name"
class="ClassName"
cascade="all|none|save-update|delete"
outer-join="true|false|auto"
update="true|false"
insert="true|false"
property-ref="propertyNameFromAssociatedClass"
access="field|property|ClassName"
unique="true|false" />


column (optional): The name of the column.

class (optional - defaults to the property type determined by reflection): The name of the associated class.

1. If we do not supply both column and class how does reflection in
hibernate work ?
2. If we supply just the column and not the class how does reflection in
hibernate work ? Does the column_name need to be the same as
the primary key name on some table ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Reflection works as always in Java: java.lang.reflect.*

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
In other words, Reflection is a concept used in Java, it has no relationship with any database schema.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 12:45 pm 
Newbie

Joined: Mon Aug 16, 2004 2:00 pm
Posts: 7
christian wrote:
In other words, Reflection is a concept used in Java, it has no relationship with any database schema.


<many-to-one name="parentCategory"
cascade="none"
outer-join="false"
foreign-key="FK1_PARENT_CATEGORY_ID">
<column name="PARENT_CATEGORY_ID"
not-null="false"
unique-key="UNIQUE_NAME_AT_LEVEL"/>
</many-to-one>

In the example above how is it known that the many-to-one mapping is to the same type of class "Category" ?

And the in case below how does it know that this many-one mapping is to the item class ?

<many-to-one
name="item"
column="ITEM_ID"
update="false"
cascade="none"
not-null="true"
outer-join="false"
access="org.hibernate.auction.persistence.DirectSetAccessor"
foreign-key="FK1_ITEM_ID"/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Because it "looks at your Java classes" to figure that out. I don't know how to simplify "Reflection" more, please read a Java book ;)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 5:50 pm 
Newbie

Joined: Mon Aug 16, 2004 2:00 pm
Posts: 7
christian wrote:
Because it "looks at your Java classes" to figure that out. I don't know how to simplify "Reflection" more, please read a Java book ;)


Thanks. I was just trying to understand how the introspection algorithm works (especially with hbm2java).


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