Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: HHH: UserCollectionType usage/sample/hints
PostPosted: Sat Feb 05, 2005 11:52 am 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
I'm trying to understand if H3's UserCollectionType is the candidate solver for my problem.

I need to wrap an object set/one-to-many collection into a "legacy" collection handler.

Classical Parent->Child association but Parent doesn't return a simple Set but a "LazyFilterableSet" so that I can iterate through a subset of the result (it should query only the subset I'm asking because there are too many childrens).

I've got this "LazyFilterableSet" interface almost everywhere in my legacy model as a standard collection interface in one-to-many relations.

I haven't found too much documentation about UserCollectionType but it seems the paradigma needed by my application.

My "LazyFilterableSet" interface simply is a Set with some more methods such as iterate(String filter) that allow me to specify a filter in the form "fieldname = 'foo' and bar = 0" and most of the time I simply could do simple search and replace and add them to an HQL query to iterate this subset.

Is such UseCase implementable by UserCollectionType? I've looked at the source code for AbstractCollectionPersister , PersistentSet and mostly QueryableCollection! It seems that everything is just already there and I simply should create a LazyFilterablePersistentSet extending PersistentSet and implementing LazyFilterableSet (my business interface) and create my support method that access protected PersistentSet method to query the collection: am I right?

How can I specify my UserCollectionType in the mapping?

_________________
Stefano Bagnara


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 1:05 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
I'm looking for a solution for Hibernate 2: after more investigation i've found that the Set returned by hibernate2 is a net.sf.hibernate.Set and it allow me to use the method "w(String condition)" to obtain an iterator over a filtered collection.

I can create a wrapper for my LazyFilterableSet that take a net.sf.hibernate.Set as input and convert my "filter string" into "odmg filter string" (or HQL filter?). My filters are in the form "property = value and otherproperty < othervalue" and I think I should only change this to call the method select("from this where this.property = value and this.otherproperty < othervalue"); am I right?

Is there a way in hibernate 2 to have my business method to aumatically return this wrapper instead of that collection?

_________________
Stefano Bagnara


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 6:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, in HB2 you have to extend th einternal class net.sf.hibernate.type.PersistentCollectionType. That's why we introduced the UserCollectionType in HB3.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 9:45 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
Hibernate2 (I know this is not the best forum for this, but this is the topic)
I'm not sure how should I implement this.

I added LazyFilterableSetHibernateImpl an implementation of LazyFilterableSet extending net.sf.hibernate.collection.Set and extended net.sf.hibernate.type.SetType with my LazyFilterableSetType. I simply took SetType and replaced every java.util.Set with my.package.LazyFilterableSetHibernateImpl .

And now? I don't understand what to write in the mapping! the <set> tag doesn't accept "class", "type", "persister" or anything similar. I thought I should have found a generic <collection> "tag" to map my specific userCollection.

And what about the same thing in Hibernate3 ?

_________________
Stefano Bagnara


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 9:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In HB3 there is a collection-type attribute of <set>, etc.

In HB2.1 you will need to do some fancy manipulation of the cfg metamodel.

I really don't know why you are trying to do this in 2.1.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 05, 2005 10:20 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
gavin wrote:
In HB3 there is a collection-type attribute of <set>, etc.

In HB2.1 you will need to do some fancy manipulation of the cfg metamodel.

I really don't know why you are trying to do this in 2.1.


Ok, that's perfect for me: I just need informations :-)

The application is already 2.1 and I'm preparing for porting to 3.0 by refactoring: I want to do every possible refactoring step in 2.1 because 3.0 is not in stable release status and not officially supported in spring (i'm using an home-made port of the spring-hibernate-support).

Thank you for your help! google's says that this "custom" collection handling is not so common and it is not easy to find samples and/or documentation!

By now I've created a LazyFilterableSetWrapper that take as an argument an hibernate Set and proxy my request and added a further method to my Business object so that the LazyFilterSet getCollection() will create a LazyFilterableSetWrapper(getStandardCollection()) and getStandardCollection is mapped by hibernate!

I'll take next steps for post 3.0 release!

_________________
Stefano Bagnara


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 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.