-->
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.  [ 1 post ] 
Author Message
 Post subject: How to initialize user collection types
PostPosted: Sat Jan 05, 2008 2:32 am 
Newbie

Joined: Mon Nov 19, 2007 9:01 am
Posts: 8
Hibernate version: 3.2.4

Using a UserCollectionType - all is working great! Except I just want to check how to initialize it with arbitrary properties.

In the non-persistent case, if I wanted the collection to have a reference back to the parent I would just do something like:

Code:
public class MyClass {
   IMyCollection mycoll = new MyCollection(this);
}


In the persistent case, though, that line doesn't actually instantiate the MyCollection instance - it's instantiated at some later time by the persister calling the UserCollectionType subclass, neither of which has a reference to the MyClass instance.

So here's what I've done:
1. Added a setMyClass method to the IMyCollection interface
2. Added a MyClass property to the persister. Note that setMyClass() in the persister can't just delegate to setMyClass() in the wrapped set, because the wrapped set might not yet be instantiated, so...
3. In the persister, overridden beforeInitialize() to call set.setMyClass(...).

The idea being to set properties on the wrapped set after it has been instantiated but before it gets used.

The question is, is this the right place to be doing this? AbstractPersistentCollection.initialize() might seem more natural, but it's final.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.