ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hett <hetthat...@gmail.com>
Subject RE: TypeHandler UUID
Date Wed, 21 Feb 2007 14:53:06 GMT

getResult() is not being called at all, but it does went to setParameter().
This is what I have in my resultmap

<sqlMap namespace="Person">

  <typeAlias alias="person" type="domain.Person"/>  

  <resultMap id="get-all" class="person">
	<result property="id" column="person_id"
typeHandler="domain.UUIDTypeHandler"/>
  </resultMap>

  <select id="getPersonById" resultMap="get-all"
parameterClass="java.util.UUID">
    SELECT
          *
    FROM person
    WHERE person_id=#value#
  </select>

</sqlMap>


Niels Beekman-2 wrote:
> 
> Hi,
> 
> Is getResult() being called? If not, try adding an explicit
> javaType="java.util.UUID" to the resultmap.
> 
> If I may suggest an optimization: replace getter.getObject() == null
> with getter.wasNull().
> 
> Niels
> 
> -----Original Message-----
> From: hett [mailto:hetthatroi@gmail.com] 
> Sent: woensdag 21 februari 2007 1:15
> To: user-java@ibatis.apache.org
> Subject: TypeHandler UUID
> 
> 
> Hi, I am working with a db that doesn't support UUID, so we specify the
> id
> column in the db as an nvarchar(36).  I follow this example
> http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+u
> se+a+Custom+Type+Handler+with+complex+property+or+Type+Safe+Enumeration
> and created my TypeHandler.
> 
> In my person class, I have the following:
> 
> public class Person {
> 	UUID id;
>                 //get and set method...
> }
> 
> and in UUIDTypeHandler:
> 
> public class UUIDTypeHandler implements TypeHandlerCallback{
> 
> 	public Object getResult(ResultGetter getter) throws SQLException
> {
> 		String value = getter.getString();
> 		if(getter.getObject() == null){
> 			return null;
> 		}
> 		UUID uuid = UUID.fromString(value);
> 		return uuid;
> 	}
> 
> 	public void setParameter(ParameterSetter setter, Object
> parameter) throws
> SQLException {
> 		if(parameter == null){
> 			setter.setNull(Types.VARCHAR);
> 		}else{
> 			UUID uuid = (UUID) parameter;
> 			//System.out.println(uuid.toString());
> 			setter.setString(uuid.toString());
> 		}
> 	}
> 
> 	public Object valueOf(String s) {
> 		return s;
> 	}
> }
> 
> in the sqlmapconfig I added this:
> <typeHandler javaType="java.util.UUID"
> callback="domain.UUIDTypeHandler"/>
> 
> I tried to do a select query, but the result is always null, is there
> something else I am missing?
> -- 
> View this message in context:
> http://www.nabble.com/TypeHandler-UUID-tf3264136.html#a9073293
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/TypeHandler-UUID-tf3264136.html#a9082175
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Mime
View raw message