Temporary tables created in SQLServer use the collation for tempdb, not the application database

Description

The use of temporary tables for updates in SQLServer will fail if tempdb uses a different collation to the application db. Specifically, comparisons between the primary table columns and the temporary table columns fail.

It is unclear to me under what circumstances a temporary table is created, so I'm afraid no test case is attached. I do however attach modified versions of the following classes:

org.hibernate.mapping.Table
org.hibernate.dialect.Dialect
org.hibernate.dialect.SQLServerDialect

These resolve the issue, but the solution may not be the most optimal possible, as it involves intervention in a specific position (between the datatype declaration and any nullability clause)

Environment

SQLServer (All versions)

Activity

Show:
David Good
June 3, 2008, 3:42 PM

Fix to allow annotation to be varied depending on column type

David Good
June 3, 2008, 3:45 PM

Add column parameter to getCreateTemporaryTableColumnAnnotation

David Good
June 3, 2008, 3:52 PM

The older versions of the attachments should disregarded - they will cause a failure if any of the temporary table's columns is not of the *char variety.

Fran├žois DAMBRINE
August 14, 2020, 12:44 PM

As of 5.4.19 the bug is still there and prevent some update query to be executed as seen in

Is there a workaround for this bug?

Nathan Xu
August 14, 2020, 6:13 PM

I created a PR for it here:

Assignee

Nathan Xu

Reporter

David Good

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure