-->
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: Need help with a UserType that's not working
PostPosted: Fri Jul 02, 2010 1:31 pm 
Newbie

Joined: Fri Jul 02, 2010 1:19 pm
Posts: 3
Hello

I've written a custom UserType to deal with a legacy database storing texts as ASCII strings with HTML escapes (instead of, say, UTF8 or some other binary charset.) I'm trying to do the encoding and decoding on the UserType level.

This is the code (standard part collapsed):

Code:
public class HtmlStringType implements UserType
{
   public HtmlStringType() {}
   private static int[] sqlTypes = new int[] { Types.VARCHAR };
   public int[] sqlTypes() { return sqlTypes; }
   public Class returnedClass() { return String.class; }
   public boolean isMutable() { return false; }
   public Object assemble(Serializable cached, Object owner) { return cached; }
   public Serializable disassemble(Object value) { return (Serializable) value; }
   public Object replace(Object original, Object target, Object owner) { return original; }
   public int hashCode(Object x) { return x.hashCode(); }
   public boolean equals(Object x, Object y) { return (x == y) || (x != null && x.equals(y)); }
   public Object deepCopy(Object o) { return o == null ? null : new String((String) o); }

   public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o)
      throws SQLException
   {
      String val = (String) Hibernate.STRING.nullSafeGet(inResultSet, names[0]);
      return StringEscapeUtils.unescapeHtml(val);
   }

   public void nullSafeSet(PreparedStatement inPreparedStatement, Object o, int i)
      throws SQLException
   {
      String val = (String) o;
      inPreparedStatement.setString(i, StringEscapeUtils.escapeHtml(val));
   }
}

I have applied it to some String properties using @Type. I made sure that the @Type annotation is being recognized, because if I return more than an element in the sqlTypes() array, I get a "property mapping has wrong number of columns" error.

Still my nullSafeGet() method is never entered (I checked with a debugger) and so my custom string encoding / decoding never happens. What am I missing?

Edit: I'm using 3.5.2-Final


Last edited by tobia.conforto on Wed Jul 07, 2010 1:15 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Custom UserType not being called
PostPosted: Wed Jul 07, 2010 12:15 pm 
Newbie

Joined: Fri Jul 02, 2010 1:19 pm
Posts: 3
Does anybody have any idea?


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.