Thanks for the quick reply, I just learned java for a few weeks, still trying
to get use to eclipse, can you show me how to enable debug logging to see
the generate query?
here is my dbAccess method using generic:
public T getObjectById(String query, UUID id) {
T rObject = null;
// reset the error
this.error = "";
try {
rObject = (T)sqlMap.queryForObject(query, id);
} catch (SQLException e) {
// System.out.println(e);
this.error = e.getMessage();
}
return rObject;
}
and here is my testing code:
DBAccess<Person> ac = new DBAccess<Person>();
Person p = ac.getObjectById("getPersonById",
UUID.fromString("A26A19F6-18C4-4ba0-84BB-6EAD12B4CB8D"));
System.out.println(p.getId());
I have tested my DBAccess with a different object using the String type and
I got data back, so I don't think it's my DBAccess code is the problem.
Niels Beekman-2 wrote:
>
> Try to enable debug logging and see if you get results when you manually
> execute the generated query. getResult() should definitely be called, so
> I think it's either a bug in your setParameter() or the query is wrong.
> Could you post your calling Java code too?
>
> Niels
>
> -----Original Message-----
> From: hett [mailto:[EMAIL PROTECTED]
> Sent: woensdag 21 februari 2007 15:53
> To: [email protected]
> Subject: RE: TypeHandler UUID
>
>
> 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:[EMAIL PROTECTED]
>> Sent: woensdag 21 februari 2007 1:15
>> To: [email protected]
>> 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.
>
>
>
--
View this message in context:
http://www.nabble.com/TypeHandler-UUID-tf3264136.html#a9084307
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.