-->
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.  [ 1 post ] 
Author Message
 Post subject: Synchronize java instances with the database
PostPosted: Tue May 29, 2007 12:25 pm 
Beginner
Beginner

Joined: Tue Nov 09, 2004 12:22 pm
Posts: 44
Hello,

I'm using Hibernate v3.2.0 GA and HSQLDB V1.8.0.7.

I'm also using Spring to manage the transactions with the DB.

I have a class called "Tournoi" that is mapped in DB. There is a collection called matches which is an association to a class called "Match" that is also mapped. The Tournoi class has also an association to another mapped class called "Classement".

First, I create a new instance of Tournoi and I initialize a Set of Match that I associate to Tournoi. Presently each Match has no score.
I save Tournoi in the DB.

In another class, I execute a query to get all matches from a specific day.
The user can modify a match at a time.
The changes are updated in the DB.

The instance of Tournoi and its collections have not changed.

I would like to still have the Tournoi instance synchronized with the database.

Indeed, when I want to calculate the ranking (Classement class), I would like to save the whole collection and not each element of the collection (the first solution seems to work faster).

If I choose the first solution, as the instance of Tournoi and its collections have not changed, all modifications of the Set of matches will be replaced in the DB by the Set of matches (without modifications - no score).

What is the good practice ? Should I call "refresh" before updating the Tournoi instance. Do java instances always have to be synchronized with the database or not necessarily ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.