-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: problem with SQL-server's uniqueidentifier
PostPosted: Mon May 29, 2006 6:02 am 
Newbie

Joined: Mon May 29, 2006 5:23 am
Posts: 7
Hello,

I have problems while trying to retrieve information from a SQL-server 2000 database. The problem occurs when i use a table which has a uniqueidentifier as primary key.

The ID in my class is of type Long, and somehow the JDBC driver cannot convert the uniqueidentifier to a Long value. This is the exception:

[java] Hibernate: select test0_.ID as ID0_, test0_.Naam as Naam0_, test0_.Postcode as Postcode0_, test0_.Datum as Datum0_, test0_.Verplicht as Verplicht0_ from tbl__Test_1 test0_
[java] 11:36:42,234 INFO LongType:132 - could not read column value from result set: ID0_; [Microsoft][SQLServer 2000 Driver for JDBC]Value can not be converted to requested type.
[java] 11:36:42,234 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: HY000
[java] 11:36:42,234 ERROR JDBCExceptionReporter:72 - [Microsoft][SQLServer 2000 Driver for JDBC]Value can not be converted to requested type.
[java] org.hibernate.exception.GenericJDBCException: could not execute query
[java] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.loader.Loader.doList(Loader.java:2148)
[java] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
[java] at org.hibernate.loader.Loader.list(Loader.java:2024)
[java] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
[java] at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
[java] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
[java] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
[java] at tests.TestManager.listTests(Unknown Source)
[java] at tests.TestManager.main(Unknown Source)
[java] Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Value can not be converted to requested type.
[java] at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
[java] at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
[java] at com.microsoft.jdbc.base.BaseData.getLong(Unknown Source)
[java] at com.microsoft.jdbc.base.BaseResultSet.getLong(Unknown Source)
[java] at com.microsoft.jdbc.base.BaseResultSet.getLong(Unknown Source)
[java] at org.hibernate.type.LongType.get(LongType.java:28)
[java] at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
[java] at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
[java] at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
[java] at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:554)
[java] at org.hibernate.loader.Loader.doQuery(Loader.java:689)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
[java] at org.hibernate.loader.Loader.doList(Loader.java:2145)

The mapping file for my test-class:

<hibernate-mapping>
<class name="tests.Test" table="tbl__Test_1">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="naam" column="Naam"/>
<property name="postcode" column="Postcode"/>
<property name="datum" type="timestamp" column="Datum"/>
<property name="verplicht" column="Verplicht"/>
</class>
</hibernate-mapping>

Does anyone know how to work with this "uniqueidentifier"?

Kind Regards,
Martijn van Hagen


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 8:07 am 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
The hibernate documentation tells us to do it like this:

Code:
<id name="id" type="long" column="person_id">
<generator class="sequence">
<param name="sequence">person_id_sequence</param>
</generator>
</id>


Code:
<id name="id" type="long" column="person_id" unsaved-value="0">
<generator class="identity"/>
</id>


You can use native for identity columns with auto increment

Good Luck

Sorry did not read this correct this one is for identity.....

_________________
DonĀ“t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 11:46 am 
Newbie

Joined: Mon Sep 13, 2004 8:20 am
Posts: 7
Location: Poland
Try:

<id name="id" column="ID">
<generator class="native"/>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 11:47 am 
Newbie

Joined: Mon Sep 13, 2004 8:20 am
Posts: 7
Location: Poland
Sorry for wrong post

Try:

<id name="id" column="ID">
<generator class="uuid"/>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 9:57 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
SQLServers convert to strings, not longs. Change your POJO so that the ID is String.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 9:57 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Oops.

^SQLServers^SQLServer uniqueidentifiers

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.