-->
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.  [ 5 posts ] 
Author Message
 Post subject: one to one relationship
PostPosted: Thu Oct 05, 2006 10:25 pm 
Beginner
Beginner

Joined: Thu Oct 06, 2005 8:14 pm
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:[/b]

[b]Mapping documents:[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using:[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

I have been really strugging with some thing for the last couple of days
This is what I want to achieve
Person has a bank account has one contact
Contact has many phones many addresses etc
so when I set bankaccount to null I want the contact tree to disappear
this isn't happening I don;t know how to do thi
I first modelled bank account as a composite element then made it an entity as well.. but does not seem to cut it


<class name="BankAccount" table="BankAccount" lazy="true">
<id name="id" type="integer" column="id">
<generator class="native"/>
</id>

<property name="accountName">
<column name="Account_Name"/>
</property>
<property name="branch">
<column name="Branch"/>
</property>
<property name="accountNumber">
<column name="Account_Number"/>
</property>
<property name="bsb">
<column name="BSB"/>
</property>
<property name="bankName">
<column name="BankName"/>
</property>

<many-to-one name="bankContact" column="Contact_Id" unique="true" class="com.tramada.contact.model.Contact" cascade="all"/>


and I have in person a bag of bankaccounts
now when i set the bankaccount to be null i.e I delete the bank account reasonable expectation contact should disappear as well but only bank account disappears and not contact
Really struggling with this and I feel like breaking my head against a wall
I don't seem to see teh same thing in the test cases of hiberante

Can anyone help....
Can anyone help me..........


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 11:59 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
In your person class, set the cascade to be all-delete-orphan for the bankcontact mapping. That way, if you remove the Bankaccount from the person, it should cascade down to the bankcontacts. Check Section 21.3. Cascading lifecycle from the Ref docs for similar info.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 1:34 am 
Beginner
Beginner

Joined: Thu Oct 06, 2005 8:14 pm
Posts: 23
Thanks for your reply but I already have a cascade all there that covers scade delete all orphans as well... That did not work
Regards
Subu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 1:46 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Cascade "all" is not the same as cascade "all-delete-orphan" i.e. "all" does not include orphan delete.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 2:09 am 
Beginner
Beginner

Joined: Thu Oct 06, 2005 8:14 pm
Posts: 23
thanks for that I read the specs a little bit more carefully
A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance

Get a runtime exception though when I do add that ...Let me debug it a bit more


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