-->
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: Problems when merge()-ing AnyType objects
PostPosted: Tue Oct 03, 2006 5:37 am 
Newbie

Joined: Tue Oct 03, 2006 5:24 am
Posts: 2
Hi,
not sure whether this is a bug or misuse, but I have an object containing a AnyType-reference (with cascade=all) that under some circumstances may be null. If I then try to merge in an object that has content for the AnyType-reference, the merge() fails with a NullPointerException in AnyType.isModified(), when Hibernate tries to check whether the anytype-object has been updated. The problem seems to be that the "old"-value is a ObjectTypeCacheEntry with both entityname and id set to null. The last call to equals()-below then fails:

Code:
(In org.hibernate.type.AnyType:)

   public boolean isModified(Object old, Object current, boolean[] checkable, SessionImplementor session)
   throws HibernateException {
      if (current==null) return old!=null;
      if (old==null) return current!=null;
      ObjectTypeCacheEntry holder = (ObjectTypeCacheEntry) old;
(*)      if (holder.entityName==null) return current!=null;
      boolean[] idcheckable = new boolean[checkable.length-1];
      System.arraycopy(checkable, 1, idcheckable, 0, idcheckable.length);
      return ( checkable[0] && !holder.entityName.equals( session.bestGuessEntityName(current) ) ) ||
            identifierType.isModified(holder.id, getIdentifier(current, session), idcheckable, session);
   }



I added the line marked with an (*), which seems to fix the problem. The intention of the check being something like "If the entityname is not set, but the current object is, then there probably was an update". Of course, I haven't got a clue whether the code fills the intention, or if there is a basic flaw in my design :-)

I'll run with this patch for now, but it would be good with feedback on whether its a good fix or just bad assumptions.
Code:
Code:

_________________
- Trond


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.