Always Encrypt with Hibernate

The first problem was i was using encrypted column in order by clause that is not being supported.
The second issue seems to be while inserting record. here is my finding as of now# In org.hibernate.persister.entity.AbstractEntityPersister# it gives anonymous implementation of Binder which internally calls org.hibernate.type.AbstractStandardBasicType and String data type of a POJO is being converted to org.hibernate.type.descriptor.sql.VarcharTypeDescriptor. So while setting the properties in insert statement in PreparedStatement it will use setString() method for “nvarchar” data type db columns instead of setNString(), which results in exception# com.microsoft.sqlserver.jdbc.SQLServerException: Operand type clash: varchar(3) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK_Auto1', column_encryption_key_database_name = 'employee') collation_name = 'SQL_Latin1_General_CP1_CI_AS' is incompatible with nvarchar(255) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK_Auto1', column_encryption_key_database_name = 'employee').

this is clearly mentioned in# https://docs.microsoft.com/en-us/sql/connect/jdbc/using-always-encrypted-with-the-jdbc-driver

The setter method used for the parameter targeting the SSN column is setString(), which maps to the char/varchar SQL Server data type. If, for this parameter, the setter method used was setNString(), which maps to nchar/nvarchar, the query would fail, as Always Encrypted does not support conversions from encrypted nchar/nvarchar values to encrypted char/varchar values.

I guess we will need to make some changes in Hibernate or i might be missing some properties which could have done this.