-->
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.  [ 12 posts ] 
Author Message
 Post subject: Why is == based identity.....
PostPosted: Sun Oct 17, 2004 3:49 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
better than id based identity and could you provide examples of why?


many thanks


Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 17, 2004 5:19 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please start reading the documentation and this page: http://www.hibernate.org/109.html

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


Top
 Profile  
 
 Post subject: Hi Christian...
PostPosted: Sun Oct 17, 2004 7:25 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
I have read the article you pointed me to. My problem is this, I have a parent class which can have any number of associated child items. The parent ID is used as a foreign key in the child class. How can I acheive the same thing by implementing a 'a good equals() method'?? - (www.hibernate.org/109.html - Seperating object id and business key).

My maps are as follows:

[b]Order.htm.xml[b/]

<hibernate-mapping package="test">
<class name="Order" table="orderstbl">
<id name="ID" column="order_id" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<property name="OrderDate" column="order_date" type="timestamp" not-null="true"/>
<property name="PriceTotal" column="price_total" type="double" not-null="true"/>
<property name="UserID" column="user_id" type="integer" not-null="true"/>
<set name="OrderItems" table="orderitemstbl" inverse="true" cascade="all">
<key column="order_id"/>
<one-to-many class="OrderItem"/>
</set>
</class>
</hibernate-mapping>

[b]OrderItems.hbm.xml[b/]

<hibernate-mapping package="test">
<class name="OrderItem" table="orderitemstbl">
<id name="ID" column="orderitem_id" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<property name="OrderID" column="order_id" type="string" not-null="true" insert="false" update="false"/>
<property name="StockID" column="stock_id" type="string" not-null="true" insert="false" update="false"/>
<property name="Amount" column="amount" type="integer"/>
<property name="Price" column="price" type="double"/>
<many-to-one name="Order" class="Order" column="order_id" />
<many-to-one name="Stock" class="Stock" column="stock_id"/>
</class>
</hibernate-mapping>

many thanks in advance


Andrew


Top
 Profile  
 
 Post subject: Could anybody out there...
PostPosted: Sun Oct 17, 2004 9:23 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
please point me in the right direction where I can see code which shows me how to amend my maps so that I can take advantage of equal(). As shown in my maps, i have specified a parent class which has a one-to-many association with a child class. At the moment the id's for each class are being generated and only being made available after being saved session.save(), where as i wish to be able to associate different child items to a parent before saving the parent. I already have a set specified in my parent map:

<class name="Order" table="orderstbl">
<id name="ID" column="order_id" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<property name="OrderDate" column="order_date" type="timestamp" not-null="true"/>
<property name="PriceTotal" column="price_total" type="double" not-null="true"/>
<property name="UserID" column="user_id" type="integer" not-null="true"/>

<set name="OrderItems" table="orderitemstbl" inverse="true" cascade="all">
<key column="order_id"/>
<one-to-many class="OrderItem"/>
</set>
</class>

To take advantage of equal() can i use the following?:

<set name="OrderItems" table="orderitemstbl" inverse="true" cascade="all">
<key column="order_id"/>
<property name="OrderDate" column="order_date" type="timestamp" not-null="true"/>
<property name="UserID" column="user_id" type="integer" not-null="true"/>
<one-to-many class="OrderItem"/>
</set>

What about the id line, do i remove that? so my parent map now looks like:

<class name="Order" table="orderstbl">


<property name="PriceTotal" column="price_total" type="double" not-null="true"/>

<set name="OrderItems" table="orderitemstbl" inverse="true" cascade="all">
<key column="order_id"/>
<property name="OrderDate" column="order_date" type="timestamp" not-null="true"/>
<property name="UserID" column="user_id" type="integer" not-null="true"/>
<one-to-many class="OrderItem"/>
</set>
</class>

Could someone please please point me in the right direction here as I deadline that is very quickly running away from me here!


many thanks in advance


Andrew


Top
 Profile  
 
 Post subject: Where is the love peeps!?
PostPosted: Sun Oct 17, 2004 11:26 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
We need to start spreading the wealth around here! I have read the article http://www.hibernate.org/109.html which tells me what one should do in terms of you [b]'using a set of properties for equals() that identify your individual objects'[b/], what I would like to know now is how to apply that in the real world terms. As i have said before I have a one to many association on a parent/child relationship, the parent id being used as a foreign key in the child. My first port of call is to know how to amend my maps to reflect this, my second being the code i would use to update/delete from the parent/child association?

if someone could point me in the right direction I would be most greatfull.


many thanks again

Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 17, 2004 11:28 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Man, its sunday, have some patience. This is a "spare time help" forum, not a commercial support tool were everyone jumps on your questions immediately.

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


Top
 Profile  
 
 Post subject: I hear what you are saying brother.....
PostPosted: Sun Oct 17, 2004 11:32 am 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
and if I had anymore hair to pull out, trust me I would! As I have no more hair to pull out, I can now only be but patient ;-)


regards


Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 17, 2004 5:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why don't you just do as the 109.html pages eplain ?
Add a equals method which uses the best natural key....(remember if you dont have a unique natural key THEN == is probably the best candidate, right ? (think about it))

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Max...
PostPosted: Sun Oct 17, 2004 5:58 pm 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
first of all i am new to this game.. so I am a bit like a man fumbling in the dark.. and what I am fumbling for at the moment is syntax examples. I would like to see examples of how to define my maps for starters and then the corresponding hibernate code to take advantage of the maps, do you have or could you point my in the direction of any examples please.


many thanks


Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 17, 2004 5:59 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Get the Hibernate in Action ebook if the examples on the website and documentation are not enough.

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


Top
 Profile  
 
 Post subject: Re: Max...
PostPosted: Sun Oct 17, 2004 6:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
There are a tons of examples at the hibernate.org site under documentation / and as christian says, if that is not enough then get the book.

But besides that go look in the unit test cases or maybe even try to make middlegen generate hbm.xml for you if you have an existing db....it will make a best first shot mapping for you.

if you have hbm.xml then you could try using hbm2java to generate matching java code....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Sun Oct 17, 2004 6:03 pm 
Regular
Regular

Joined: Fri Oct 08, 2004 4:11 am
Posts: 78
Location: Nottingham, England
all for the help you have given me on this issue, I will purchase Hibernate in Action book as you mention.


many regards


Andrew


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