-->
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.  [ 3 posts ] 
Author Message
 Post subject: Why all rows are updated without any change?
PostPosted: Wed Aug 08, 2007 11:11 am 
Newbie

Joined: Mon Oct 16, 2006 2:34 am
Posts: 4
When I start a transaction, load all rows of a table and then commit() it, hibernate runs an UPDATE-SQL for each row.
I haven't even touched the objects!

Where do I have to dig?

Thanks
Urs


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 11:18 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Hibernate thinks your objects have changed. You've probably got a bug in a getter/setter method of your class.


Top
 Profile  
 
 Post subject: Why all rows are updated without any change?
PostPosted: Thu Aug 09, 2007 10:52 am 
Newbie

Joined: Mon Oct 16, 2006 2:34 am
Posts: 4
Thanks fo the hint.

In fact it was a nullable primitive issue.

I solved it by creating a NullableIntType, but made a mistake in there.

Now, by using java.lang.Integer rather than int I could solve it much smoother.

I post the Type just for completeness. Maybe someone can help me with it. Some methodes I have no clou what it wants :-)

Code:
/**
*
*
*
*/
package model;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;

/**
* @author uf
*
*/
public class NullableIntType implements UserType {
   private static final int[] SQL_TYPES = {Types.NUMERIC};
   

   /**
    *
    */
   public NullableIntType() {
      // TODO Auto-generated constructor stub
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable, java.lang.Object)
    */
   public Object assemble(Serializable arg0, Object arg1)
         throws HibernateException {
      // TODO Auto-generated method stub
      return null;
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
    */
   public Object deepCopy(Object obj) throws HibernateException {
      return new Integer(obj.toString());
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
    */
   public Serializable disassemble(Object arg0) throws HibernateException {
      // TODO Auto-generated method stub
      return null;
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#equals(java.lang.Object, java.lang.Object)
    */
   public boolean equals(Object x, Object y) throws HibernateException {
      return x == y;
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
    */
   public int hashCode(Object x) throws HibernateException {
      return new Integer(x.hashCode());
   }


   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#isMutable()
    */
   public boolean isMutable() {
      return false;
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object)
    */
   public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
         throws HibernateException, SQLException {
      if ( resultSet.wasNull() ) return new Integer(0);
      return resultSet.getInt(names[0]);
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
    */
   public void nullSafeSet(PreparedStatement statement, Object value, int index)
         throws HibernateException, SQLException {
      if ( value == null ){
         statement.setNull(index, Types.NUMERIC);
      }
      else {
         statement.setInt(index, new Integer(value.toString()));
      }

   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#replace(java.lang.Object, java.lang.Object, java.lang.Object)
    */
   public Object replace(Object arg0, Object arg1, Object arg2)
         throws HibernateException {
      // TODO Auto-generated method stub
      return null;
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#returnedClass()
    */
   public Class returnedClass() {
      return int.class;
   }

   /* (non-Javadoc)
    * @see org.hibernate.usertype.UserType#sqlTypes()
    */
   public int[] sqlTypes() {
      return SQL_TYPES;
   }

}


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