-->
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: UserType isn't working on Oracle, but on other DBs
PostPosted: Fri Jun 13, 2008 5:27 am 
Newbie

Joined: Tue May 20, 2008 12:21 pm
Posts: 4
Hello,

I implemented a UserType to right trim strings saved in a char column based on the example on CustomStringTrimTypeH3. The UserType is working well on DB2 and MsSql, but not on Oracle. Saven an entity is possible, but if I search the insertet entity (it's in the db) I can't find it. The statement always returns NULL (nothing found). I don't get an exception. If I execute the generated statement directly on the DB, it's working.

Thanks for your help!

Regards,
Thomas

Hibernate version:
3.2.5

Mapping documents:
Code:
@Entity
@Table(name = "ISOV_USER")
public class AuthIsovUser extends AbstractTechnicalDomainEntity
{
   /**
    * userId
    */
   private String userId;

   /**
    * Default Constructor for AuthIsovUser
    */
   public AuthIsovUser()
   {
      super();
      version = -1;
   } // End of Default Constructor - AuthIsovUser

   /**
    * Setter-method for userId
    * @param pUserId Object to set
    */
   public void setUserId(String pUserId)
   {
      this.userId = pUserId;
   } // End of Method - setUserId

   /**
    * Getter-method for userId
    * @return Instance of userId
    */

   @org.hibernate.annotations.Type(type = "com.ibm.isov.framework.common.persistence.TrimmedCharUserType")
   @Column(name = "USER_ID", unique = true, insertable = true, updatable = true, nullable = false, columnDefinition = "char(14)", length = 14)
   public String getUserId()
   {
      return this.userId;
   } // End of Method - getUserId

   /**
    * Method to get the version of the entity.
    * @return the version
    */
   @Version
   @Column(name = "VERSION")
   public int getVersion()
   {
      return version;
   }

   /**
    * Method to set the version of the entity.
    */
   public void setVersion(int pVersion)
   {
      version = pVersion;
   }
} // End of Class - AuthIsovUser


Name and version of the database you are using:
Oracle 10.2.0.1.0

The generated SQL (show_sql=true):
Code:
select authisovus0_.IU_ID as IU1_4_, authisovus0_.CREATE_DATE as CREATE2_4_, authisovus0_.CREATE_USER as CREATE3_4_, authisovus0_.UPDATE_DATE as UPDATE4_4_, authisovus0_.UPDATE_ORGUNIT as UPDATE5_4_, authisovus0_.UPDATE_RELEASE as UPDATE6_4_, authisovus0_.UPDATE_USER as UPDATE7_4_, authisovus0_.defaultUserDetails_IUD_ID as default14_4_, authisovus0_.FIRST_NAME as FIRST8_4_, authisovus0_.LAST_NAME as LAST9_4_, authisovus0_.USER_ID as USER10_4_, authisovus0_.VALID_FROM as VALID11_4_, authisovus0_.VALID_TO as VALID12_4_, authisovus0_.VERSION as VERSION4_ from ISOVDBUSER.ISOV_USER authisovus0_ where authisovus0_.USER_ID=?


The UserType Implementation
Code:
package com.ibm.isov.framework.common.persistence;

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

import org.hibernate.Hibernate;
import org.hibernate.usertype.UserType;

/**
* Custom class for trimming strings on the way out from the database
*/
public class TrimmedCharUserType implements UserType
{
   /**
    * default constructor
    */
   public TrimmedCharUserType()
   {
   }

   /**
    * @see org.hibernate.usertype.UserType#sqlTypes()
    */
   public int[] sqlTypes()
   {
      return new int[] { Types.CHAR };
   }

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

   /**
    * @see org.hibernate.usertype.UserType#equals(java.lang.Object, java.lang.Object)
    */
   public boolean equals(Object x, Object y)
   {
      return (x == y) || (x != null && y != null && (x.equals(y)));
   }

   /**
    * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object)
    */
   public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o) throws SQLException
   {
      String val = (String) Hibernate.STRING.nullSafeGet(inResultSet, names[0]);
      return rightTrim(val);
   }

   /**
    * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
    */
   public void nullSafeSet(PreparedStatement inPreparedStatement, Object o, int i) throws SQLException
   {
      String val = (String) o;
      inPreparedStatement.setString(i, val);
   }

   /**
    * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
    */
   public Object deepCopy(Object o)
   {
      if (o == null)
      {
         return null;
      }
      return new String(((String) o));
   }

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

   /**
    * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable, java.lang.Object)
    */
   public Object assemble(Serializable cached, Object owner)
   {
      return cached;
   }

   /**
    * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object)
    */
   public Serializable disassemble(Object value)
   {
      return (Serializable) value;
   }

   /**
    * @see org.hibernate.usertype.UserType#replace(java.lang.Object, java.lang.Object, java.lang.Object)
    */
   public Object replace(Object original, Object target, Object owner)
   {
      return original;
   }

   /**
    * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
    */
   public int hashCode(Object x)
   {
      return x.hashCode();
   }
   
   /**
    * Method used for removing trailing whitespaces.
    *
    * @param input <code>String</code> to trim.
    * @return <code>String</code> without any trailing whitespaces.
    */
   public String rightTrim(String input) {
      if (null != input)
      {
         return input.replaceAll("\\s+$", "");
      }
      return null;
   }
}


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.