-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate mapping for VARBINARY(16)
PostPosted: Thu Sep 02, 2010 2:34 am 
Newbie

Joined: Tue Aug 31, 2010 8:46 am
Posts: 1
Using JDBC, I create a row in MYSQL table using this code:

Insert:
Connection conn = getConnection();
Statement s = conn.createStatement();

String uuid = UUID.randomUUID().toString();
uuid = uuid.replace("-", "");
uuid = "0x"+ uuid;
s.executeUpdate("INSERT INTO table1 SET idtable1="+uuid+", name='x'");
s.close();

fetch:
Connection conn = getConnection();
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery(
"SELECT hex(idtable1), name FROM table1 where hex(idtable1)='C283E11848BD4F888FFF31BA4E3307EF'");
int i=0;
while(rs.next())
{
System.out.println ("FETCHED UUID IS " + rs.getString(1) + " FETCHED NAME IS " + rs.getString(2));
i++;
}

s.close();

Using Hibernate,
When I create hbm mapping file, VARBINARY converts to byte[] and not to String.
How can I map the same to String rather than byte[]? I am not able to proceed with the code.

In one word, how to achieve the above functionality in hibernate code?


Top
 Profile  
 
 Post subject: Re: Hibernate mapping for VARBINARY(16)
PostPosted: Wed Sep 08, 2010 8:07 am 
Newbie

Joined: Wed Sep 08, 2010 8:03 am
Posts: 1
java.util.UUID.nameUUIDFromBytes(byte[]).toString() should work just fine.


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