How do I query UUIDs stored as binary in a database (JPA/Hibernate/MySQL) -
How do I query UUIDs stored as binary in a database (JPA/Hibernate/MySQL) -
i have java/jpa/hibernate/mysql based app. want utilize uuids object identity, want ensure database performance not suffer.
i found great blog posting jpa , uuid primary keys gets me of way there. notice how storage of uuid optimized storing in binary form (versus string representation.
it solves part of problem, because can insert objects efficiently database.
however, have issue when want query database using entitymanager.createquery. possible/desirable query against binary data? or, should store string uuid along-side binary version facilitate querying?
tested hibernate 4.1.2 , mysql-connector-j 5.1.18, can define uuid field:
@entity class entitytype { @column( columndefinition = "binary(16)", length = 16 ) private uuid id; }
...and query uuid instance:
uuid id = ....; entitytype result = em.createquery( “select x entitytype x x.id = ?1″, entitytype.class ) .setparameter( 1, id ).getsingleresult();
hibernate jpa binary uuid
Comments
Post a Comment