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: Comparator should not need to vanish
PostPosted: Fri Oct 21, 2005 2:28 am 
Newbie

Joined: Thu Oct 20, 2005 11:52 am
Posts: 6
Hi,

I was wondering what the problem would be if Hibernate would pick up the Comparator instance (class) used for it's Set.

I have declared a Set like:


Code:
private SortedSet<Order> deals = new TreeSet<Order>(new CloseDateDescComparator());


Because Hibernate replaces the SortedSet implementation with it's own, i lose the Comparator. This can as far as i see, only be resolved by setting the sort atribute on the set.


Code:
<set name="deals" sort="CloseDateDescComparator">


Are my assumptions right. If so why can't hibernate pick up the comparator from the initialized TreeSet before it replaces it.
If this can be done easier, please let me know as well.

cheers,

Raphael


Top
 Profile  
 
 Post subject: 2c
PostPosted: Fri Oct 21, 2005 6:04 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Probably because H does not expect the field to be initialized on your class, it can be declared as
private SortedSet<Order> deals;
and H will be able to work,
http://www.hibernate.org/hib_docs/v3/re ... ons-sorted

Kind of make sense for me. Sensing current Comparator probaly is not a good idea because potentially somebody sets comparator at runtime and then spend days trying to figure out why mapping file specifies one sorting order and it is not working

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 2:35 am 
Newbie

Joined: Thu Oct 20, 2005 11:52 am
Posts: 6
Konstantin,

You are probaly right, but the other is true too (i went trough it ;) ): looking why the comparator just disapeared.

I guess the wise thing would be that Hibernate would generate a warning when it notices the developer initiliazes the SortedSet with a Comparator.

tx.,

Raphael


Top
 Profile  
 
 Post subject: mental models
PostPosted: Tue Oct 25, 2005 10:45 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Just 2c:
My mental model of H is like this: H uses configuration file and static type information to take care of persistence. (Populate instance from database, “merge” instance and state). Therefore I do not think that H should introspect runtime state of an object and try to adjust own behavior to the state. I think it would be too much room for confusion.

In the end, it is up to H team to decide.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.