-->
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.  [ 7 posts ] 
Author Message
 Post subject: GlazedLists and Hibernate integration
PostPosted: Wed Dec 27, 2006 7:13 am 
Beginner
Beginner

Joined: Tue Dec 26, 2006 3:50 pm
Posts: 22
Hibernate version: 3.2.1

Mapping documents:

Code:
<class name="User" table="`USERS`">
        <id name="userName" column="USERNAME"/>
        <!-- mapping a value collection -->
        <list name="nickNames" table="USER_NICKNAMES"
            collection-type="ca.odell.glazedlists.hibernate.EventListType">
            <key column="USER_ID"/>
            <list-index column="DISPLAY_ORDER"/>
            <element column="NAME" type="string" length="50"/>
        </list>
  </class>


I have two questions with regard to the implementation of a UserCollectionType for a BasicEventList of the GlazedLists project http://www.publicobject.com/glazedlists/.
The current state of this EventListType and the corresponding PersistentEventList is available here:
https://glazedlists.dev.java.net/source ... hibernate/

This solution basically works as shown above with a mapping example.
There are two problems remaining:

1.) customizing EventList creation

The EventListType is responsible for creating the PersistentCollection and the wrapped collection, in this case a BasicEventList.
There are situations where we want to customize the creation of the EventLists, for example pass in a dedicated ReadWriteLock object.

Therefore, it would be helpful, if the CustomCollectionType EventListType could implement
Code:
org.hibernate.usertype.ParameterizedType
to pass in some external parameters. But this isn't supported currently, correct?
Would it be possible to implement this enhancement in Hibernate?

2.) transparent lazy loading of list elements

EventLists fire events to attached ListEventListeners when adding, removing or setting list elements.
When Hibernate loads the elements and fills the list during initialization, already attached list event listeners will receive corresponding events, which isn't desired in this case.
The idea is to temporarily disable the event notification during list initialization and enable it again afterwards.

What are the correct methods to implement/override in PersistentEventList?

My guess would be:

Code:
void beforeInitialize(CollectionPersister persister, int anticipatedSize)
boolean afterInitialize()


Is this correct or is there another way to accomplish this?


Thanks for your help,
Holger


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 6:51 am 
Beginner
Beginner

Joined: Tue Dec 26, 2006 3:50 pm
Posts: 22
So let me rephrase my questions:

1.)
Missing support of ParameterizedTypes for custom collection types seems to be an oversight or nobody asked for it yet.
As there is now demand for it, would you be willing to add this enhancement to Hibernate?
Let me know if I should file a JIRA issue...

We need to do something like this:
Code:
<typedef class="ca.odell.glazedlists.hibernate.EventListType" name="MyCollectionType">
    <param name="category">Test</param>
</typedef>

<class name="User" table="`USERS`">
        <id name="userName" column="USERNAME"/>
        <!-- mapping a value collection -->
        <list name="nickNames" table="USER_NICKNAMES"
            collection-type="MyCollectionType">
            <key column="USER_ID"/>
            <list-index column="DISPLAY_ORDER"/>
            <element column="NAME" type="string" length="50"/>
        </list>
</class>


2.)
What's the recommended way to intercept the loading of lazy-mapped collections to take some action before and after the collection elements are loaded?

The two methods I mentioned before seem to be called also for non-lazy collections.

TIA,
Holger


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 11:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
1) org.hibernate.usertype.ParameterizedType is an *interface*... Just implement it...

2) Yes, between paired calls to beforeInitialize and afterInitialize you would want to disable your notifications...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 11:27 am 
Beginner
Beginner

Joined: Tue Dec 26, 2006 3:50 pm
Posts: 22
I tried it, but got the exception below:

Using this mapping, where EventListType implements UserCollectionType and ParameterizedType:

Code:
<typedef name="MyEventListType" class="ca.odell.glazedlists.hibernate.EventListType">
        <param name="category">Test</param>
</typedef>
<class name="User" table="`USERS`">
        <id name="userName" column="USERNAME"/>
        <!-- mapping a value collection -->
        <list name="nickNames" table="USER_NICKNAMES"
            collection-type="MyEventListType">
            <key column="USER_ID"/>
            <list-index column="DISPLAY_ORDER"/>
            <element column="NAME" type="string" length="50"/>
        </list>       
</class>


Exception trace:

Code:
org.hibernate.MappingException: user colllection type class not found: MyEventListType
   at org.hibernate.type.TypeFactory.customCollection(TypeFactory.java:267)
   at org.hibernate.mapping.Collection.getCollectionType(Collection.java:348)
   at org.hibernate.mapping.Collection.getType(Collection.java:340)
   at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:120)
   at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:163)
   at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:425)
   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
   at ca.odell.glazedlists.hibernate.AbstractHibernateTestCase.buildSessionFactory(AbstractHibernateTestCase.java:133)
   at ca.odell.glazedlists.hibernate.AbstractHibernateTestCase.setUp(AbstractHibernateTestCase.java:167)
   at junit.framework.TestCase.runBare(TestCase.java:125)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: MyEventListType
   at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Class.java:164)
   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
   at org.hibernate.type.TypeFactory.customCollection(TypeFactory.java:264)
   ... 24 more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 7:39 am 
Beginner
Beginner

Joined: Tue Dec 26, 2006 3:50 pm
Posts: 22
So the stacktrace indicates that Hibernate interprets the value of the collection-type attribute always as class name. It does not consider typedef'ed types.
In addition, the parameters have to be injected as done for UserTypes and CompositeUserTypes (TypeFactory.injectParameters(...)).

Can you confirm this?
Will you implement this enhancement in Hibernate?

Thanks,
Holger


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 31, 2006 6:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, the functionallity you describe sounds correct (+ we probably need to throw an error if you start mix-match value and collection custom types)

I probably won't do such implementation right now; but I do encourage you (or others) to write a patch + unittests to get the ball rolling.

At least report it in jira ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 31, 2006 9:40 am 
Beginner
Beginner

Joined: Tue Dec 26, 2006 3:50 pm
Posts: 22
Ok, done.
For those who are interested, here is the issue reference:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2336

Thanks,
Holger


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