When writing a HQL query with a CAST function to a nationalizes string, there is different behavior between Hibernate 5 and Hibernate 6, with property hibernate.use_nationalized_character_data set to true. HQL:
[...] CAST(name AS nstring) [...]
Oracle SQL (Hibernate 5)
[...] CAST(name AS nvarchar2(4000)) [...]
Oracle SQL (Hibernate 6)
[...] CAST(name AS varchar2(4000)) [...]
So in Hibernate 5, cast to nstring would produce the nationalized type nvarchar2(4000) and in Hibernate 6, it will produce the non-nationalized type varchar2(4000). I would expect a cast to nstring to produce a cast to nvarchar2(4000) in (Oracle) SQL, just like in Hibernate 5. Cause In BaseSqmToSqlAstConverter, there is a method visitCastTarget that decides on the SQL type for the cast. It uses InferredBasicValueResolver.resolveSqlTypeIndicators with an nstring as 'resolved'. This causes the code path to eventually jump to NVarcharJdbcType.resolveIndicatedType, which will produce Types.VARCHAR, because indicators.isNationalized() returns false. indicators here is a StandardSqmTranslator, which doesn't provide an overridden method for isNationalized. |