-->
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.  [ 6 posts ] 
Author Message
 Post subject: 3.0b4 and UserCollectionType interface changes
PostPosted: Fri Feb 11, 2005 4:01 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
Hibernate version:
3.0b4

In hibernate 3.0b3 I implemented my custom UserCollection by adding a new class (HibernateHQLPersistentSet) extending PersistentSet and implementing my own collection business interface and adding a new class implementing UserCollectionType (HibernateHQLSetType) defined as follow:

Code:
public class HibernateHQLSetType implements UserCollectionType {

   public PersistentCollection instantiate(SessionImplementor arg0,
         CollectionPersister arg1) throws HibernateException {
      return new HibernateHQLPersistentSet(arg0);
   }

   public PersistentCollection wrap(SessionImplementor arg0, Object arg1) {
      return new HibernateHQLPersistentSet(arg0, (Set) arg1);
   }

}


When I upgraded to hibernate 3.0b4 I found that I should implement the following methods of the UserCollectionType interface!

Code:
   /**
    * Optional operation. Does the collection contain the entity instance?
    */
   public boolean contains(Object collection, Object entity);
   /**
    * Optional operation. Return the index of the entity in the collection.
    */
   public Object indexOf(Object collection, Object entity);


What should I do if I don't want to implement the optional methods? Should I throw an UnsupportedOperationException?

Code:
   
   /**
    * Return an iterator over the elements of this collection - the passed collection
    * instance may or may not be a wrapper
    */
   public Iterator getElementsIterator(Object collection);

   /**
    * Replace the elements of a collection with the elements of another collection
    */
   public void replaceElements(
         Object original,
         Object target,
         CollectionPersister persister,
         Object owner,
         Map copyCache,
         SessionImplementor session)
         throws HibernateException;
   
   /**
    * Instantiate an empty instance of the "underlying" collection (not a wrapper)
    */
   public Object instantiate();


Should I simply change my own HibernateHQLSetType that was only implementing UserCollectionType by extending UserCollectionType or better SetType?

_________________
Stefano Bagnara


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 4:12 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
I tested the "extend" solution but also extending SetType doesn't fix all the problems: there are still methods to be implemented... Why SetType doesn't need to implement this methods while a UserCollectionType does?

the replaceElements and the no-argument instantiate are not there.

Why and when this methods are called? What are they supposed to do?

_________________
Stefano Bagnara


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 4:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
SetType inherits them from CollectionType.

You only need to implement these methods if you plan to use unidirectional one-to-many associations with <key column=".." not-null="true"/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 8:38 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
gavin wrote:
SetType inherits them from CollectionType.


Then I believe there's a bug because that's not true:

UserCollectionType define:
Code:
public void replaceElements(
         Object original,
         Object target,
   >>>   CollectionPersister persister,      <<<
         Object owner,
         Map copyCache,
         SessionImplementor session)
         throws HibernateException;


CollectionType define:
Code:
public Object replaceElements(
         Object original,
         Object target,
         Object owner,
         Map copyCache,
         SessionImplementor session)
         throws HibernateException {


some difference also apply to "public Object instantiate()".

gavin wrote:
You only need to implement these methods if you plan to use unidirectional one-to-many associations with <key column=".." not-null="true"/>


Ok, thank you for the explanation!

_________________
Stefano Bagnara


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 8:47 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 4:54 am
Posts: 25
I see in sources that CustomCollectionType does this:

Code:
   public Object replaceElements(Object original, Object target, Object owner, Map copyCache, SessionImplementor session)
   throws HibernateException {
      CollectionPersister cp = session.getFactory().getCollectionPersister( getRole() );
      userType.replaceElements(original, target, cp, owner, copyCache, session);
      return target;
   }


I assume that I simply should add the replaceElement and call the replaceElement from "super" taking away the persister.

What about the instantiate?
I get a call to instantiate() with no arguments while my superclass (SetType) only implements instantiate(Object o)... what should be passed to that superclass method?

_________________
Stefano Bagnara


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 10:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Just because the argument list is different, don't assume the semantics are different.


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