ibatis-user-java mailing list archives

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

Hi, I am working with a db that doesn't support UUID, so I 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+use+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.


Mime
View raw message