-->
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: Synchronize in-memory instances with persistance
PostPosted: Tue Dec 26, 2006 8:23 pm 
Beginner
Beginner

Joined: Tue Nov 09, 2004 12:22 pm
Posts: 44
Hibernate version:
3.2.0 GA

Mapping documents:

Tournoi.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.2

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.pescorer.business.Tournoi"
table="TOURNOI"
lazy="false"
>

<id
name="numero"
type="java.lang.Long"
column="NUMERO"
>

<generator class="native" />
</id>

<property
name="type"
type="java.lang.Integer"
column="TYPE"
not-null="true"
/>

<!-- Associations -->

<!-- bi-directional one-to-many association to Participant -->

<set
name="participants"
lazy="true"
inverse="true"
cascade="all"

>
<key>
<column name="NUM_TOURNOI" />
</key>

<one-to-many
class="com.pescorer.business.Participant"
/>
</set>
<!-- bi-directional one-to-one association to Championnat -->
<one-to-one
name="championnat"
class="com.pescorer.business.Championnat"
outer-join="auto"
/>
<!-- bi-directional one-to-many association to Match -->

<set
name="matches"
lazy="true"
inverse="true"
cascade="all"
order-by="numero asc"

>
<key>
<column name="NUM_TOURNOI" />
</key>

<one-to-many
class="com.pescorer.business.Match"
/>
</set>
<!-- bi-directional one-to-one association to Coupe -->
<one-to-one
name="coupe"
class="com.pescorer.business.Coupe"
outer-join="auto"
/>
<!-- bi-directional one-to-many association to Classement -->

<set
name="classements"
lazy="true"
inverse="true"
cascade="all"

>
<key>
<column name="NUM_TOURNOI" />
</key>

<one-to-many
class="com.pescorer.business.Classement"
/>
</set>
<!-- bi-directional many-to-one association to Saison -->
<many-to-one
name="saison"
class="com.pescorer.business.Saison"
not-null="true"
>
<column name="NUM_SAISON" />
</many-to-one>

</class>
</hibernate-mapping>

Match.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.2

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.pescorer.business.Match"
table="MATCH"
lazy="false"
>

<id
name="numero"
type="java.lang.Long"
column="NUMERO"
>

<generator class="native" />
</id>

<property
name="nbButs1"
type="java.lang.Integer"
column="NB_BUTS1"
/>
<property
name="nbButs2"
type="java.lang.Integer"
column="NB_BUTS2"
/>
<property
name="prolongations"
type="java.lang.Boolean"
column="PROLONGATIONS"
/>
<property
name="penalties"
type="java.lang.Boolean"
column="PENALTIES"
/>
<property
name="nbPenalties1"
type="java.lang.Integer"
column="NB_PENALTIES1"
/>
<property
name="nbPenalties2"
type="java.lang.Integer"
column="NB_PENALTIES2"
/>
<property
name="groupe"
type="java.lang.Integer"
column="GROUPE"
/>
<property
name="journee"
type="java.lang.Integer"
column="JOURNEE"
/>
<property
name="tour"
type="java.lang.Integer"
column="TOUR"
/>
<property
name="forfait"
type="java.lang.Boolean"
column="FORFAIT"
not-null="true"
/>
<property
name="verrouille"
type="java.lang.Boolean"
column="VERROUILLE"
not-null="true"
/>

<!-- Associations -->

<!-- bi-directional many-to-one association to Tournoi -->
<many-to-one
name="tournoi"
class="com.pescorer.business.Tournoi"
not-null="true"
>
<column name="NUM_TOURNOI" />
</many-to-one>
<!-- bi-directional many-to-one association to UtilisateurParticipant -->
<many-to-one
name="utilisateurParticipantByNumUtilisateurParticipant1"
class="com.pescorer.business.UtilisateurParticipant"
not-null="true"
>
<column name="NUM_UTILISATEUR_PARTICIPANT1" />
</many-to-one>
<!-- bi-directional many-to-one association to UtilisateurParticipant -->
<many-to-one
name="utilisateurParticipantByNumUtilisateurParticipant2"
class="com.pescorer.business.UtilisateurParticipant"
not-null="true"
>
<column name="NUM_UTILISATEUR_PARTICIPANT2" />
</many-to-one>
<!-- bi-directional one-to-many association to Stat -->

<set
name="stats"
lazy="true"
inverse="true"
cascade="all"

>
<key>
<column name="NUM_MATCH" />
</key>

<one-to-many
class="com.pescorer.business.Stat"
/>
</set>

</class>
</hibernate-mapping>


Name and version of the database you are using:

HSQLDB 1.8.0

I have a Tournoi instance in memory with a collection of Matches. This instance is persistent (session.save(tournoi) has been done).
Then, I retrieve a new collection of matches with a Criteria query.
I make some changes in some matches of that collection and if I write the following :
Code:
List matches = tournoi.getMatches();
...
Match match = ... (Match) iterator.next();
System.out.println(match.toString());


I still have the old match. I must load the tournoi again from the DB to get the up-to-date collection.
Is any way to synchronize this collection ?

I know that a question almost similar had been asked but I was wondering if it has something to do with detached instances...
It seems strange that there is not any automatic process managed by Hibernate.


Last edited by speedster on Tue Dec 26, 2006 8:29 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 26, 2006 8:28 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
session.refresh(object)

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 6:07 pm 
Beginner
Beginner

Joined: Tue Nov 09, 2004 12:22 pm
Posts: 44
scarface wrote:
session.refresh(object)


It does not work. I refreshed the "Tournoi" object but the collection still have the old values for the matches that have changed.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 6:18 pm 
Newbie

Joined: Mon Feb 05, 2007 9:16 pm
Posts: 4
If you're still having this problem, have you tried session.flush() after you make changes to your Tournoi object's collection? That is, if you're making the query in the same transaction as the changes to the Tournoi object.


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.