Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 61483 invoked from network); 1 Mar 2010 07:36:55 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Mar 2010 07:36:55 -0000 Received: (qmail 25532 invoked by uid 500); 28 Feb 2010 09:50:15 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 25481 invoked by uid 500); 28 Feb 2010 09:50:14 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 25471 invoked by uid 99); 28 Feb 2010 09:50:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Feb 2010 09:50:13 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of vikram.s@directi.com designates 122.182.1.139 as permitted sender) Received: from [122.182.1.139] (HELO smtp.directi.com) (122.182.1.139) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Feb 2010 09:50:03 +0000 Received: from lp-vikram.s-ubuntu (unknown [122.167.91.244]) by smtp.directi.com (Postfix) with ESMTPA id 792EA46D8091 for ; Sun, 28 Feb 2010 15:19:37 +0530 (IST) Message-ID: <4B8A3C18.80805@directi.com> Date: Sun, 28 Feb 2010 15:19:12 +0530 From: Vikram Subbarao User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: user-java@ibatis.apache.org Subject: Re: java.util.UUID to postgres uuid column References: <4B713A84.1070201@directi.com> <4B73A8AB.5070500@directi.com> <50CA25BD6EEA954FA592C097399942E31A75E752@CM1.wis.local> <4B73BC01.20301@directi.com> <00ce01caab0d$91556de0$b40049a0$@com> <4B74FFB8.4040301@directi.com> In-Reply-To: <4B74FFB8.4040301@directi.com> Content-Type: multipart/alternative; boundary="------------070104090102000304060201" --------------070104090102000304060201 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello All, Any idea on this? Regards Vikram Vikram Subbarao wrote: > The uuid in database is stored in a column of type uuid supported by > postgres db. Now when i use the query below, i am passing a string and > would become VARCHAR to database which results in postgres db > complaining that it cannot compare 'Character Varying' and 'uuid' > values. I understand implicit casts happen in certain databases (like > sql server), but not in postgres. > > Also, there are performance issues shuttling between UUID (128 bits) > and String (36 Chars for type 4 uuid = 576 bits) and then back for a > frequent query like this which seems mostly un-necessary if ibatis > could understand and add this as a known type, especially since > postgress jdbc supports java.util.UUID as a type. > > Regards > Vikram > > meindert wrote: >> >> Hi Vikram, >> >> >> >> I don't use the UUID myself and can't answer your question from >> experience, but I think the real question would be how the ID is >> stored in the DB. >> >> IBATIS error message is is correct to say that the UUID object does >> not have a value (like a string or int object) and there is no >> UUID.getId() >> >> Assuming you use a 'uniqueidentifier' type on the (sql server) db >> side, I would think you need to query the ID as a string; >> >> >> >> >> >> sqlMapClientTemplate.queryForObject("User.findById", id.toString()); >> >> >> >> From sql books online: >> >> A column or local variable of *uniqueidentifier* data type can be >> initialized to a value in the following ways: >> >> * By using the NEWID function. >> * By converting from a string constant in the >> form/xxxxxxxx/-/xxxx/-/xxxx/-/xxxx/-/xxxxxxxxxxxx/, in which >> each /x/ is a hexadecimal digit in the range 0-9 or a-f. For >> example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a >> valid *uniqueidentifier* value. >> >> Comparison operators can be used with *uniqueidentifier* values. >> However, ordering is not implemented by comparing the bit patterns of >> the two values. The only operations that can be performed against >> a *uniqueidentifier* value are comparisons (=, <>, <, >, <=, >=) and >> checking for NULL (IS NULL and IS NOT NULL). No other arithmetic >> operators can be used. All column constraints and properties, except >> IDENTITY, can be used on the *uniqueidentifier* data type. >> >> Merge replication and transactional replication with updating >> subscriptions use*uniqueidentifier* columns to guarantee that rows >> are uniquely identified across multiple copies of the table. >> >> >> >> Regards >> >> Meindert Hoving >> >> >> >> >> >> *From:* Vikram Subbarao [mailto:vikram.s@directi.com] >> *Sent:* 11 February 2010 10:13 AM >> *To:* user-java@ibatis.apache.org >> *Subject:* Re: java.util.UUID to postgres uuid column >> >> >> >> Does not work - >> >> com.ibatis.common.beans.ProbeException: There is no READABLE >> property named 'value' in class 'java.util.UUID' >> >> Niels Beekman wrote: >> >> Try #value#, this will use your parameter object directly. Using #id# >> tries to obtain the id property from it. >> >> >> >> ------------------------------------------------------------------------ >> >> *From:* Vikram Subbarao [mailto:vikram.s@directi.com] >> *Sent:* Thursday, February 11, 2010 7:50 AM >> *To:* user-java@ibatis.apache.org >> *Subject:* Re: java.util.UUID to postgres uuid column >> >> >> >> With this approach i tried this in a query - >> >> >> >> >> When i call this query as - >> >> sqlMapClientTemplate.queryForObject("User.findById", id); >> >> / Note: id is an java.util.UUID object./ >> >> I get an error - >> >> com.ibatis.common.beans.ProbeException: There is no READABLE >> property named 'id' in class 'java.util.UUID' >> >> Regards >> Vikram >> >> Larry Meadors wrote: >> >> This might work: >> >> public class UUIDTypeHandler implements TypeHandlerCallback { >> @Override >> public void setParameter(ParameterSetter setter, Object parameter) >> throws SQLException { >> setter.setObject(parameter); >> } >> >> @Override >> public Object getResult(ResultGetter getter) throws SQLException { >> return getter.getObject(); >> } >> >> @Override >> public Object valueOf(String s) { >> return UUID.fromString(s); >> } >> } >> >> Add this in your sqlmapconfig.xml: >> >> >> >> >> Larry >> >> >> >> On Tue, Feb 9, 2010 at 3:35 AM, Vikram Subbarao wrote: >> >> >> I am using postgres db and would like to map a java.util.UUID to a postgres >> >> uuid column. Latest postgres driver supports mapping of this if i was >> >> directly creating my prepared statements but since i use ibatis inbetween, i >> >> am unable to achive this as ibatis does not seem to understand that >> >> java.util.UUID can be based down to jdbc. I could use typehandler if the db >> >> column was a VARCHAR, but since the postgres db is a 'uuid' type, i have no >> >> option but to use the driver supported option of using java.util.UUID, but >> >> it does not work with ibatis for me. >> >> >> >> Please help me if some one has a solution to this. >> >> >> >> Regards >> >> Vikram >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >> >> For additional commands, e-mail: user-java-help@ibatis.apache.org >> >> >> >> >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org >> For additional commands, e-mail: user-java-help@ibatis.apache.org >> >> >> >> No virus found in this incoming message. >> Checked by AVG - www.avg.com >> Version: 9.0.733 / Virus Database: 271.1.1/2676 - Release Date: >> 02/10/10 21:38:00 >> --------------070104090102000304060201 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hello All,

Any idea on this?

Regards
Vikram


Vikram Subbarao wrote:
The uuid in database is stored in a column of type uuid supported by postgres db. Now when i use the query below, i am passing a string and would become VARCHAR to database which results in postgres db complaining that it cannot compare 'Character Varying' and 'uuid' values. I understand implicit casts happen in certain databases (like sql server), but not in postgres.

Also, there are performance issues shuttling between UUID (128 bits) and String (36 Chars for type 4 uuid = 576 bits) and then back for a frequent query like this which seems mostly un-necessary if ibatis could understand and add this as a known type, especially since postgress jdbc supports java.util.UUID as a type.

Regards
Vikram

meindert wrote:

Hi Vikram,

 

I don’t use the UUID myself and can’t answer your question from experience, but I think the real question would be how the ID is stored in the DB.

IBATIS error message is is correct to say that the UUID object does not have a value (like a string or int object) and there is no UUID.getId()

Assuming you use a ‘uniqueidentifier’  type on the (sql server) db side, I would think you need to query the ID as a string;

 

    <select id="findById" parameterClass="string" resultMap="fullResult" cacheModel="cache">
        SELECT users.*
        FROM users
        WHERE id = #value#
    </select>   


sqlMapClientTemplate.queryForObject("User.findById", id.toString());

 

From sql books online:

A column or local variable of uniqueidentifier data type can be initialized to a value in the following ways:

  • By using the NEWID function.
  • By converting from a string constant in the formxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, in which each x is a hexadecimal digit in the range 0-9 or a-f. For example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid uniqueidentifier value.

Comparison operators can be used with uniqueidentifier values. However, ordering is not implemented by comparing the bit patterns of the two values. The only operations that can be performed against a uniqueidentifier value are comparisons (=, <>, <, >, <=, >=) and checking for NULL (IS NULL and IS NOT NULL). No other arithmetic operators can be used. All column constraints and properties, except IDENTITY, can be used on the uniqueidentifier data type.

Merge replication and transactional replication with updating subscriptions useuniqueidentifier columns to guarantee that rows are uniquely identified across multiple copies of the table.

 

Regards

 Meindert Hoving

 

 

From: Vikram Subbarao [mailto:vikram.s@directi.com]
Sent: 11 February 2010 10:13 AM
To: user-java@ibatis.apache.org
Subject: Re: java.util.UUID to postgres uuid column

 

Does not work -

    com.ibatis.common.beans.ProbeException: There is no READABLE property named 'value' in class 'java.util.UUID'

Niels Beekman wrote:

Try #value#, this will use your parameter object directly. Using #id# tries to obtain the id property from it.

 


From: Vikram Subbarao [mailto:vikram.s@directi.com]
Sent: Thursday, February 11, 2010 7:50 AM
To: user-java@ibatis.apache.org
Subject: Re: java.util.UUID to postgres uuid column

 

With this approach i tried this in a query -

    <select id="findById" parameterClass="java.util.UUID" resultMap="fullResult" cacheModel="cache">
        SELECT users.*
        FROM users
        WHERE id = #id#
    </select>   



When i call this query as -

    sqlMapClientTemplate.queryForObject("User.findById", id);

    Note: id is an java.util.UUID object.

I get an error -

    com.ibatis.common.beans.ProbeException: There is no READABLE property named 'id' in class 'java.util.UUID'

Regards
Vikram

Larry Meadors wrote:

This might work:
 
public class UUIDTypeHandler implements TypeHandlerCallback {
    @Override
    public void setParameter(ParameterSetter setter, Object parameter)
throws SQLException {
        setter.setObject(parameter);
    }
 
    @Override
    public Object getResult(ResultGetter getter) throws SQLException {
        return getter.getObject();
    }
 
    @Override
    public Object valueOf(String s) {
        return UUID.fromString(s);
    }
}
 
Add this in your sqlmapconfig.xml:
 
<typeAlias alias="UUID" type="java.util.UUID" />
<typeHandler javaType="UUID" callback="UUIDTypeHandler"/>
 
Larry
 
 
 
On Tue, Feb 9, 2010 at 3:35 AM, Vikram Subbarao <vikram.s@directi.com> wrote:
  
I am using postgres db and would like to map a java.util.UUID to a postgres
uuid column. Latest postgres driver supports mapping of this if i was
directly creating my prepared statements but since i use ibatis inbetween, i
am unable to achive this as ibatis does not seem to understand that
java.util.UUID can be based down to jdbc. I could use typehandler if the db
column was a VARCHAR, but since the postgres db is a 'uuid' type, i have  no
option but to use the driver supported option of using java.util.UUID, but
it does not work with ibatis for me.
 
Please help me if some one has a solution to this.
 
Regards
Vikram
 
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
 
 
    
 
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
 
  

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.733 / Virus Database: 271.1.1/2676 - Release Date: 02/10/10 21:38:00

--------------070104090102000304060201--