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: How to update detached DataObject with many to one property!
PostPosted: Fri Sep 10, 2010 2:26 am 
Newbie

Joined: Thu Sep 09, 2010 10:21 pm
Posts: 3
There is a NHibernate problem torturing me right now.I have two class,one is SysPerson,the other is SysDepartment.The relationship between the two classes is many to one. I got the SysPerson from ISession,and modify it in detached state.Any modification but the property referencing the SysDepartment will be safely updated to database.Every operation to change the property named SysDepartment will get the Exception Message:identifier of an instance of Authorization.SysDepartment was altered from 001 to 002. I just modify the reference by switch the reference to the other SysDepartment instance after the session closed.I thought the NHibernate have the ability to find the way to just change the FK value in SysPerson,but indeed NHibernate is tring to modify the PK value in SysDepartment.I think maybe there is some way to change the Mapping file to fix this problem. Please help me out of this dilemma.Thank you!


Top
 Profile  
 
 Post subject: Re: How to update detached DataObject with many to one property!
PostPosted: Fri Sep 10, 2010 6:17 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Sounds like you try to change the id of the department

sysPerson.SysDepartment.Id = "002";

That's not possible, you have to set the complete object:

sysPerson.SysDepartment = department002;

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: How to update detached DataObject with many to one property!
PostPosted: Sun Sep 12, 2010 9:19 pm 
Newbie

Joined: Thu Sep 09, 2010 10:21 pm
Posts: 3
wolli wrote:
Sounds like you try to change the id of the department

sysPerson.SysDepartment.Id = "002";

That's not possible, you have to set the complete object:

sysPerson.SysDepartment = department002;

Thanks to wolli. I did the same way you suggested, but the result let me down. I thought the problem may be the my SysPerson instance and SysDepartment instance come from different ISession. So when I set the sysPerson.SysDepartment = department002,NHibernate try to change the original SysDepartment by update its ID by department002. I go into the break point, I also found that when I have done sysPerson.SysDepartment = department002,I couldn't get the all SysDepartment from ISession,because of the same problem:identifier of an instance of Authorization.SysDepartment was altered from 001 to 002. I need the operation which load all SysDepartments information from New ISession for user to change the SysPerson's property SysDepartment that come from first ISession. Any one have suggestion for help me out.


Top
 Profile  
 
 Post subject: Re: How to update detached DataObject with many to one property!
PostPosted: Mon Sep 13, 2010 1:25 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post your code ? And the relevant part of the mapping files ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: How to update detached DataObject with many to one property!
PostPosted: Mon Sep 13, 2010 5:26 am 
Newbie

Joined: Thu Sep 09, 2010 10:21 pm
Posts: 3
wolli wrote:
Can you post your code ? And the relevant part of the mapping files ?

Thank you,Really! I fix my problem. Although I hadn't change the ID of SysDepartment, but in my code there is a databinding:[comboBox.DataBindings.Add("Value", SysDepartments, "ID")] which I want to use to present current SysDepartment.When I removed the databinding, everything is ok.What a stupid mistake I made. I think it's very careful for us to using the databinding with NHibernate detached object.


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.