Posts Tagged “MSSQL”

One of the things I have always liked doing when working with Hibernate is to use a JUnit test to run SchemaValidator against the hibernate configuration. In case you aren’t familiar, the SchemaValidator that comes with Hibernate compares the beans, the database metadata, and the Hibernate configuration and throws an exception if any discrepancies are found. By calling it from a JUnit test, you can know immediately if someone has changed any of the three pieces and broke it.

Well, today I was trying to do just that with a Microsoft SQL Server database that had tables with uniqueidentifier columns. This is a MSSQL datatype for GUIDs of the form {12345678-9ABC-DEF0-1234-56789ABCDEF0}. There is no built-in Hibernate mapping specifically for this type, although using a String in the Java object works just fine–except when using the SchemaValidator. The SchemaValidator notices that the java field is mapped to “varchar” and the database field is of type “uniqueidentifier”, which of course doesn’t match. When I modified the .hbm.xml file to specify the types on both sides explicitly, the JDBC driver threw SQLExceptions that the types could not be converted.

Anyone have success with this?

Comments No Comments »