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 ?
|