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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one association not refreshing
PostPosted: Tue Jun 13, 2006 5:10 pm 
Newbie

Joined: Fri Sep 02, 2005 3:51 pm
Posts: 17
Hi,
I have a Order class that contains a property called "statusId". The Order class also has a property called "status" that associates to another table which stores statusIds and corresponding status names.

On my jsp page, I display a bunch of orders and each order has a button that cancels the order. Also next to each order is the status name of the current status (for that order). When i click on cancel for a certain order, the order is cancelled and the action returns to the same page (with the updated status info for that order). But the status text does not change on first refresh. When I explicitly navigate to the page the status text changes.

I wrote a log statement to traverse through the orders in the action method before forwarding to the jsp and found that the "status" property of the order is not updated the first time. (the change is seen in the database and the statusId property has changed). When I refresh the db or navigate back to the page, the "status" property of order is updated and the status name changes.

I am not sure if I am clear in describing my problem, but basically hibernate does not update the "status" property immediately after the statusId is changed.

Hope someone can help me with this. My mapping files are shown below.
Thanks.

<hibernate-mapping package="com.myapp.model">
<class name="Order" table="shipping_order">
<id name="id" column="order_id" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="status"
class="com.myapp.model.OrderStatus"
column="status_id"
update="false"
insert="false"
lazy="false"
not-found="ignore"
/>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.myapp.model.OrderStatus" table="order_status">
<id name="id" column="status_id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 4:09 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
The normal way to set the status_id field would be to set the ‘status’ object (with update=”true” and insert=”true”), not the other way round. It is not likely to work that way without refreshing. If you need a method like getStatusId, in its getter method return status.getStatusId() i.e. extract the id from the status object. This way both will remain in sync.


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