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?
|