Duplicate
Details
Assignee
UnassignedUnassignedReporter
Knut WannhedenKnut WannhedenComponents
Affects versions
Priority
Major
Details
Details
Assignee
Unassigned
UnassignedReporter
Knut Wannheden
Knut WannhedenComponents
Affects versions
Priority
Created May 31, 2022 at 1:35 PM
Updated September 13, 2022 at 8:49 AM
Resolved September 13, 2022 at 8:49 AM
SQL Server uses a specific byte order when mapping Java UUID values to SQL Server
uniqueidentifier
values. See https://github.com/microsoft/mssql-jdbc/blob/62ac085563aa263415b5ac0db5cf178ba19d2d63/src/main/java/com/microsoft/sqlserver/jdbc/Util.java#L669-L701 for details.The current behavior of Hibernate is to use the standard byte order to convert a
UUID
tobyte[]
. As a result UUID values can be written to the database and can be read again. But when writing an ad-hoc SQL query with a literal UUID value in it (SQL Server will transparently convert a string to auniqueidentifier
), the query will not find the desired rows if the UUID value was obtained from the Java code (e.g. logs or some server response).As a workaround the
@Type("uuid-char")
annotation can be used, but that of course has some performance and I/O overhead.