This should be a very simple question, I just missed something basic here, and I have "one of those days ..." It is impossible to use Hibernate or another ORM. Using Java PreparedStatement.
MySQL Material:
CREATE TABLE `article` ( `articleID` binary(16) NOT NULL, `publisherID` bigint(20) DEFAULT NULL, PRIMARY KEY (`articleID`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8$$ insert into article ( articleID, publisherID ) values ( (UNHEX(REPLACE(UUID(),'-',''))), 1111 );
Java stuff
PreparedStatement ps = connection.prepareStatement( "select articleID, publisherID from article" ); ResultSet rs = ps.executeQuery(); while( rs.next()) { byte[] artIDArr = rs.getBytes( "articleID" ); UUID artID = UUID.nameUUIDFromBytes( artIDArr ); } rs.close(); ps.close();
Now, after reading the UUID from the database ...
select hex(articleID) from article; 1C711C50E4773873AB1533401E2F420C A1FCD341EE9311E297B700FFB00BB509 A95E06B6EEE611E297B700FFB00BB509
But dumping what I read in java code:
6c825dc9-c98f-37ab-b01b-416294811a84 de6337f9-f276-3e30-b9a3-8d9338a1977f 57ccb5af-1a66-329f-b069-69638e1af24f
Now, is it because I remove the dashes from the UUIDs before storing them as binary, and does rehydration assume they are there?
What is the correct method for reading a UUID stored as binary (16) in MySql for a Uavid Jav object?
Edit: if I changed the preparedStatment's request to βselect hex (articleID) as articleID ...β and read it as a string, this, of course, is what the database contains, but the UUID throws an exception because the string is missing a dash ...
java mysql uuid
Monkeywrench
source share