-->
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: @Transient field getting updated
PostPosted: Thu Mar 17, 2011 3:59 am 
Newbie

Joined: Thu Mar 17, 2011 3:32 am
Posts: 3
I have below class structure,

@Entity
@Table(name = "A")
class A
{
@OneToMany(mappedBy = "aVal")
List<B> bValues;
}

@Entity
@Table(name = "B")
class B
{
@Transient
List<C> bValues;
}

@Entity
@Table(name = "C")
class C
{

}

I do not want C table to be updated when entity of type A is saved.
However, when I do session.save(a) an update is getting fired for entity C which throws org.hibernate.StaleStateException

Please can anybody elaborate what I am doing wrong here.


Top
 Profile  
 
 Post subject: Re: @Transient field getting updated
PostPosted: Thu Mar 17, 2011 4:37 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Where is your @Id annotation? Did you always annotate fields, not getters?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: @Transient field getting updated
PostPosted: Thu Mar 17, 2011 4:40 am 
Newbie

Joined: Thu Mar 17, 2011 3:32 am
Posts: 3
mmerder wrote:
Where is your @Id annotation? Did you always annotate fields, not getters?


I have not completely described the code. There is a @Id annotation in the class I am using.
I tried using the @Transient annotation on both/on field/on getter none of them worked.


Top
 Profile  
 
 Post subject: Re: @Transient field getting updated
PostPosted: Thu Mar 17, 2011 4:58 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Well, then you need to provide more information so others can help you. Like the code inside the update-transaction and maybe the sql-statements that get submitted also.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: @Transient field getting updated
PostPosted: Thu Mar 17, 2011 6:12 am 
Newbie

Joined: Thu Mar 17, 2011 3:32 am
Posts: 3
mmerder wrote:
Well, then you need to provide more information so others can help you. Like the code inside the update-transaction and maybe the sql-statements that get submitted also.


I managed to resolve it.
I am using Spring MVC along with hibernate. The hibernate enity is being used as a Spring MVC form backing object.
A Spring SimpleFormController has two callback methods formBackingObject() and onSubmit(). (formBackingObject is called every time before onSubmit() if your form has sessionForm=false)

Earlier I was deleting/saving the C values in database in formBackingObject() callback and then saving A values in onSubmit(). Somehow the C values changed in formBackingObject() was not reflecting in the form backing object (I am using A object).

I managed to fix it by moving the C values deleting/saving code to onSubmit(). But still I am not sure why session.save(A) was calling update on C.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.