-->
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.  [ 3 posts ] 
Author Message
 Post subject: index column updates problem
PostPosted: Fri Aug 17, 2007 11:34 am 
Newbie

Joined: Fri Aug 17, 2007 11:12 am
Posts: 2
Hi all,

I have an indexed collection mapped (as part of another entity) like this:

Code:
<list name="tournamentSamples" table="USER_TOURNAMENT_SAMPLES">
         <key column="USER_ID"/>
         <list-index column="SAMPLE_INDEX"/>
         <one-to-many class="prt.TournamentSample"/>
      </list>


When the collection is updated in a new session after several changes (add, remove, modify) have been made to it while it's in the detached state, ALL the database records of the collection are updated to make the index column a progression of consecutive integers starting with 1.

Is it how it is supposed to work? or am I doing something wrong?
I am new to Hibernate. The DOC says indexed collections are fast.

What is the purpose of the index column? If one would write the (functionally equivalent) schema by hand, in plain SQL, he/she would not need index column at all.

BTW, I can't use a set instead of a list because there is no unique"business" key exist for samples.

Thank you,
Joe


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2007 1:38 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
hibernate defines the list collection as an ordered collection, based on the index column you need to define and use. If you don't need it to be ordered, and can't use a set, use a bag

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 18, 2007 12:22 pm 
Newbie

Joined: Fri Aug 17, 2007 11:12 am
Posts: 2
Thank you, Chris.

Bags was exactly what I needed. One column less.

But the updates of all records were still there. I tracked down the problem to not entirely correct implementation of the setter method for the collection. The code looked very harmless (the commented out version), but was enough to break something in Hibernate:
Code:
   protected void setTournamentSamples(List<TournamentSample> x) {
      tournamentSamples = x;
      /*
      if (x == null)
         return;
      tournamentSamples = new ArrayList<TournamentSample>();
      for (TournamentSample s: x) {
         if (s != null)
            tournamentSamples.add(s);
      }
      */
   }
As soon as I made it a one line assignment, everything started to work as expected. I guess setter methods cannot be anything else than an assignment? (what Spec or Convention say that?, - could not find it anywhere).

You know I had to use those null checks because the Hibernate was giving me lists with null elements at some point.

Thanks again,
Joe


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