There is no error, the only error I get is a null exception when I try to
println(p.getId) because p is null.
I follow the link you provided and used log4j to capture the generate query.
This is what it output when I use type String I mention earlier:
Same code, just different object(also changed the parameter of the dbAccess
to accept a String instead of UUID):
DBAccess<Activity> ac = new DBAccess<Activity>();
Activity a = ac.getObjectById("getActivityById", "10028");
System.out.println(a.getProjectId());
DEBUG [main] - {pstm-100001} Executing Statement: SELECT *
FROM activity WHERE activity_id = ?
DEBUG [main] - {pstm-100001} Parameters: [10028]
DEBUG [main] - {pstm-100001} Types: [java.lang.String]
DEBUG [main] - {rset-100002} ResultSet
DEBUG [main] - {rset-100002} Header: [activity_id, activity_type,
planned_date, short_text, description, actual_date, person_id, project_id]
DEBUG [main] - {rset-100002} Result: [10028, Meeting, null, Meet them, Meet
to discuss the discussion, null, null, 10022]
DEBUG [main] - Returned connection 3916375 to pool.
10022 //<---result
and this is the output when I used UUID:
DEBUG [main] - Created connection 3154093.
DEBUG [main] - {conn-100000} Connection
DEBUG [main] - {conn-100000} Preparing Statement: SELECT *
FROM person WHERE person_id = ?
DEBUG [main] - {pstm-100001} Executing Statement: SELECT *
FROM person WHERE person_id = ?
DEBUG [main] - {pstm-100001} Parameters:
[a26a19f6-18c4-4ba0-84bb-6ead12b4cb8d]
DEBUG [main] - {pstm-100001} Types: [java.lang.String]
DEBUG [main] - {rset-100002} ResultSet
DEBUG [main] - Returned connection 3154093 to pool.
Exception in thread "main" java.lang.NullPointerException
at
edu.neumont.ca_labs.project_tracking.testing.ActivityTester.main(ActivityTester.java:24)
//this error occurs when I tried to print the id of the person.
I am about to give up on this, I think I will just store the UUID as a
string in the objects class, but please point out if you see a problem.
Niels Beekman-2 wrote:
>
> I meant iBATIS logging, see
> http://opensource.atlassian.com/confluence/oss/display/IBATIS/How+do+I+g
> et+SqlMapClient+to+log+SQL+statements for instructions.
>
> You should gracefully handle your SQLExceptions, but for now try
> printing your "this.error" variable to see if an error occurred. Also,
> make sure that any RuntimeExceptions don't get swallowed by the code
> that calls DBAccess.getObjectById().
>
> Niels
>
> -----Original Message-----
> From: hett [mailto:[EMAIL PROTECTED]
> Sent: woensdag 21 februari 2007 17:41
> To: [email protected]
> Subject: RE: TypeHandler UUID
>
>
> 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.
>
>
>
--
View this message in context:
http://www.nabble.com/TypeHandler-UUID-tf3264136.html#a9088070
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.