-->
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: Hibernate 3.1 - Comparator not assigned to SortedSet
PostPosted: Mon Dec 05, 2005 3:31 pm 
Newbie

Joined: Mon Dec 05, 2005 3:10 pm
Posts: 2
While using Hibernate 3.1rc3 I found that my comparator was not being assigned for an internal SortedSet. This was causing a NullPointerException because my comparator was null and the internal objects in the set did not implement the Comparable interface.

This worked fine in Hibernate 2.1. I debugged the problem and found that some lazy initialization code for Comparator class creation in the org.hibernate.mapping.Collection.java
is as follows:

Code:
   public Comparator getComparator() {
      if(comparator!=null && comparatorClassName!=null) {
         try {
            setComparator( (Comparator) ReflectHelper.classForName(
               comparatorClassName ).newInstance() );
         }
         catch (Exception e) {
            throw new MappingException( "Could not instantiate comparator class: "
               + comparatorClassName + " for collection " + getRole()  );
         }
      }
      return comparator;
   }


Note the line that checks to see if a new Comparator needs to be
instantiated.
[code]if(comparator!=null && comparatorClassName!=null) {...

If I am reading this correctly it means that the initialization code for the Compartor will only be excuted if the internal comparator reference is NOT null. Meaning that the initialization code is only called when we have already initialized a Comparator which means that it will never be initialized. The logic should probably be changed to read
[code]if(comparator ==null && comparatorClassName!=null) {...
Anyway I thougt I would post this here for someone to look at who is more familiar with the way in which Hibernate lazily instantiates Comparator classes for sorted collections.
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 3:56 pm 
Newbie

Joined: Mon Dec 05, 2005 3:10 pm
Posts: 2
When I rolled back to Hibernate 3.0.5 this issue went away. I did not need to make any changes to code or mapping files.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 5:22 pm 
Newbie

Joined: Wed Nov 19, 2003 10:20 pm
Posts: 1
This seems to be a known problem with 3.1. See Jira issue HHH-1133

http://opensource2.atlassian.com/projec ... e/HHH-1133

Regards,
Bryan


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.