which is bound to a SQL Server stored procedure that receives a parameter like this:
@myField uniqueidentifier
When executed, this exception is thrown:
! com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported. ! at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServ erException.java:190) ! at com.microsoft.sqlserver.jdbc.DataTypes.throwConversionError(DataTypes.java: 1117) ! at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServer PreparedStatement.java:991)
If I change the parameter type on JDBI to String, and call it using the toString() method from the UUID object, it works:
Are you using SQL server? I had quite a bit of trouble with this, I ended up just treating them as strings. But I am just passing them back and forth through REST services anyway so I didn't really need them to be UUIDs at that level. The SQL server driver seemed to handle them fine as strings.
On Aug 19, 2012, at 9:53 AM, Fernando Correia <fernandoacorr...@gmail.com> wrote:
> which is bound to a SQL Server stored procedure that receives a parameter like this:
> @myField uniqueidentifier
> When executed, this exception is thrown:
> ! com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported.
> ! at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServ erException.java:190)
> ! at com.microsoft.sqlserver.jdbc.DataTypes.throwConversionError(DataTypes.java: 1117)
> ! at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServer PreparedStatement.java:991)
> If I change the parameter type on JDBI to String, and call it using the toString() method from the UUID object, it works:
Yes, I'm using SQL Server. Passing those parameters as string works. I'm
trying to find out if there's a way to pass them natively as UUIDs, whitout
converting to Strings.
You seem to have had the same issue I'm having.
2012/8/19 Steve Nelson <snel...@iowaballetacademy.com>
> Are you using SQL server? I had quite a bit of trouble with this, I ended
> up just treating them as strings. But I am just passing them back and forth
> through REST services anyway so I didn't really need them to be UUIDs at
> that level. The SQL server driver seemed to handle them fine as strings.
On Sun, Aug 19, 2012 at 12:01 PM, Fernando Correia
<fernandoacorr...@gmail.com> wrote:
> Yes, I'm using SQL Server. Passing those parameters as string works. I'm
> trying to find out if there's a way to pass them natively as UUIDs, whitout
> converting to Strings.
At some point, conversion is needed, but all things considered it's
unlikely that this has measurable impact on performance (wrt
conversions).
In theory, support by DB could benefit iff there is native UUID type,
to benefit from its 128-bit size. I don't know which DBs have such
native type however.
But even in those cases, as long as table definition uses UUIDs,
conversions back and forth should be efficient -- there is no magic in
there, standard 36-char representation to/from UUID is easy.
I understand. I'm not concerned about performance; that would make a very
minor difference. But all my keys are UUIDs and right now my DAO interfaces
only accept strings:
Is there a way to write a custom mapper on JDBI so I could write the
interface method accepting UUIDs, but have it convert them to string when
passing the parameter to the SqlQuery? Something like:
So the API would base based explicitly on the data types of the DTOs.
But again, without necessarily passing them along to the database as UUIDs,
just converting them to string before binding the parameters. I don't know
JDBI enough to understand if that's possible or how difficult it would be.
> At some point, conversion is needed, but all things considered it's
> unlikely that this has measurable impact on performance (wrt
> conversions).
> In theory, support by DB could benefit iff there is native UUID type,
> to benefit from its 128-bit size. I don't know which DBs have such
> native type however.
> But even in those cases, as long as table definition uses UUIDs,
> conversions back and forth should be efficient -- there is no magic in
> there, standard 36-char representation to/from UUID is easy.
fernandoacorr...@gmail.com> wrote:
> I understand. I'm not concerned about performance; that would make a very
> minor difference. But all my keys are UUIDs and right now my DAO interfaces
> only accept strings:
> Is there a way to write a custom mapper on JDBI so I could write the
> interface method accepting UUIDs, but have it convert them to string when
> passing the parameter to the SqlQuery? Something like:
> So the API would base based explicitly on the data types of the DTOs.
> But again, without necessarily passing them along to the database as
> UUIDs, just converting them to string before binding the parameters. I
> don't know JDBI enough to understand if that's possible or how difficult it
> would be.
Responded on SO with:
JDBI only exposes explicite type based bindings for the types which JDBC
exposes them for. JDBC does not expose a UUID type for binding, os it is
defaulting to setting it as an Object. Unfortunately, JDBC offers not
explicit UUID binding mechanism, so going through String is probably the
most portable way :-(
>> At some point, conversion is needed, but all things considered it's
>> unlikely that this has measurable impact on performance (wrt
>> conversions).
>> In theory, support by DB could benefit iff there is native UUID type,
>> to benefit from its 128-bit size. I don't know which DBs have such
>> native type however.
>> But even in those cases, as long as table definition uses UUIDs,
>> conversions back and forth should be efficient -- there is no magic in
>> there, standard 36-char representation to/from UUID is easy.
On Sunday, August 19, 2012 11:30:56 PM UTC-3, Brian McCallister wrote:
> JDBI only exposes explicite type based bindings for the types which JDBC > exposes them for. JDBC does not expose a UUID type for binding, os it is > defaulting to setting it as an Object. Unfortunately, JDBC offers not > explicit UUID binding mechanism, so going through String is probably the > most portable way :-(
> If you want to bind it as a UUID in Java and have it converted to a String > internally, there are two paths. The first, if you *always* want to bind > UUIDs as Strings is to use an ArgumentFactory, see > https://github.com/brianm/jdbi/blob/master/src/test/java/org/skife/jd... for > an example.