-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate UniqueIdentifier/GUID Sql Server
PostPosted: Tue Sep 13, 2016 7:56 pm 
Newbie

Joined: Mon Jun 20, 2005 9:25 am
Posts: 7
HI

I'm using hibernate with sqlserver,


I have a proceudre in sql server called using hibernate

@Override
public void getAccess() {
Query query = (Query) getSession().createSQLQuery("EXEC getAccess :name,:id,")
.addEntity(Access.class).setParameter("name", "AAA")
.setParameter("id","1dcf61b2-2b37-4c18-bad6-7b51b9ce5c61")
List<Access> result = query.list();
return ;
}

I get this error (for Id) running this, whats the correct approach to pass uniqueIdentifier

com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type nvarchar to uniqueidentifier.

Please let me know.....


Top
 Profile  
 
 Post subject: Re: Hibernate UniqueIdentifier/GUID Sql Server
PostPosted: Wed Sep 14, 2016 1:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I assume that the ID parameter is of type uniqueidentifier in your getAcess function.

Try setting the parameter like this:

Code:
.setParameter("id","1dcf61b2-2b37-4c18-bad6-7b51b9ce5c61", java.sql.Types.VARCHAR)


and see if it works. According to the SQL Server type conversion table it should work.


Top
 Profile  
 
 Post subject: Re: Hibernate UniqueIdentifier/GUID Sql Server
PostPosted: Wed Sep 14, 2016 4:01 pm 
Newbie

Joined: Mon Jun 20, 2005 9:25 am
Posts: 7
Thanks for the suggestion. But this doesnot seem to help. I'm using hibernate query and setParameter on that takes in hibernate type hence I tried with .Type.Char. But still see the same issue. Is there something I'm missing


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.