-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to persist an object which is getting refreshed
PostPosted: Wed Aug 19, 2009 7:04 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
Hi,

I am trying to save an object Item which has a price to it.
Class Item{
Price price;
}

Now, Price is an object in itself and its value changes very frequently.
So at any point of time, when I am ordering any Item it should take the price at that instance of time and save it in price table.

So when I place my 1st item, a record is persisted in ITEM table which has a foregin key for record in PRICE table. So we have a coressponding Price record in PRICE table.
But problem occurs when I place 2nd item, a record is persisted in ITEM table but no new record is inserted in PRICE table; instead the previous price record get updated with the new value.

So irrespective of the numers records in ITEM table I always have just one record in PRICE table with latest price value.

Can any one help me achieve what I am looing for?
Any inputs are appreciated.

Many thanks!


Top
 Profile  
 
 Post subject: Re: how to persist an object which is getting refreshed
PostPosted: Wed Aug 19, 2009 4:15 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Hello shagufta,
just out of curiosity did you print to a log or to console the Item unique identifier or ItemID and the Price unique identifier or PriceId on the first Item that is placed and also on subsequent items that are placed?

-Srilatha.


Top
 Profile  
 
 Post subject: Re: how to persist an object which is getting refreshed
PostPosted: Thu Aug 20, 2009 8:21 am 
Newbie

Joined: Fri May 29, 2009 2:21 am
Posts: 12
Hi Shagufta,

I think u should treat Price as a value type class associated to Item entity.
What this means is jus ask these questions,
do Price needs to be entity class (a DB identity) i.e. do they need to have a separate DB identification.

I think it can be treated as an attribute of Item. They have to be associated with identification of an Item instead of their independent identity.

I would have done below:

Item Pojo
Code:

Class Item {

Price initialPrice;
Price reservedPrice;
}


Item Table:

Item_ID
Seperate Columns for initialPrice fields
Seperate Columns for reservedPrice fields

Item HB Mapping:

I would have used Component mapping concept to persist my whole Item object.

Hope Im making sense.

Regards
Nitesh


Top
 Profile  
 
 Post subject: Re: how to persist an object which is getting refreshed
PostPosted: Thu Aug 27, 2009 8:06 am 
Regular
Regular

Joined: Fri May 22, 2009 4:50 am
Posts: 59
thanks u guys..
My problem is solved.
The problem was that i was using same price object reference for each Item.
Creating a new price for each item and copying the value in it, solved my problem.

PS: nitesh I required price to be an object and have its own db identity as the object is much more complex than i described here. thanks anyways.


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