-->
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.  [ 2 posts ] 
Author Message
 Post subject: Clob and dirty checking
PostPosted: Fri Dec 12, 2008 8:50 am 
Newbie

Joined: Mon Nov 10, 2008 8:43 am
Posts: 8
Hi All,

I have extended the ClobStringType to provide custom handling to a clob text. I am stuck with a strange problem.

This field is one of the instance variable of the managed entity. Whenever there is a change in this field only and there is no change in other instance variables (i.e. other columns) then Hibernate is not updating the managed entity.

When there is change in other columns as well, Hibernate updates the managed entity. Other fields are simple strings.

Please let me know what can I do and what possibly is going wrong here.

Here is the handler code:
Code:
public class VCardClobType extends ClobStringType {

public VCardClobType() {
      super();
   }
protected VCardClobType(LobHandler lobHandler,
         TransactionManager jtaTransactionManager) {
      super(lobHandler, jtaTransactionManager);
   }

protected Object nullSafeGetInternal(ResultSet resultSet, String[] columns,
         Object owner, LobHandler lobHandler) throws SQLException,
         HibernateException {

      
      if (columns == null || columns.length != 1)
         throw new HibernateException(
               "Only one column name can be used for the " + getClass()
                     + " user type");

      InputStream reader = lobHandler.getClobAsAsciiStream(resultSet,
            columns[0]);
      if (reader == null)
         return null;

      Contact contact = null;

      try {
         /
         contact = VCardUtil.parseContact(reader);
      } catch (Exception e) {
         throw new HibernateException("cannot read Vcard stream", e
               .getCause());

      } finally {
         if (reader != null)
            try {
               reader.close();
            } catch (Exception e) {
            }
      }

      return contact;
   }

protected void nullSafeSetInternal(PreparedStatement statement, int index,
         Object value, LobCreator lobCreator) throws SQLException,
         HibernateException {

      String vCardStr = null;
      if (value != null)
         try {

            vCardStr = VCardUtil.getVCardString((Contact) value);
         } catch (Exception e) {
            throw new HibernateException("cannot write Vcard stream", e
                  .getCause());
         }
      super.nullSafeSetInternal(statement, index, vCardStr, lobCreator);
   }

public Object deepCopy(Object value) throws HibernateException {
      if (value == null)
         return null;
      try {
         return VCardUtil.copy(((Contact) value));
      } catch (IllegalAccessException e) {
         log.error("error while copying vcard: "
               + ((Contact) value).toString());
         // e.printStackTrace();
      } catch (InvocationTargetException e) {
         log.error("error while copying vcard: "
               + ((Contact) value).toString());
         // e.printStackTrace();
      }

      return null;
   }

   public Class returnedClass() {
      return Contact.class;
   }

   public boolean isMutable() {
      return true;
   }
}


Any help would be highly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 10:25 am 
Newbie

Joined: Thu Apr 19, 2007 10:38 am
Posts: 11
Try to put a breakpoint in
Code:
public boolean equals(Object x, Object y)
from
Code:
AbstractLobType

and see what returns when only the column with VCardClobType is modified. This method is invoked by the dirty checking process to determine whether the object should is dirty and should be updated in the database or not.


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