Red Bit
Red Bit

Reputation: 485

Hibernate - How to bind parameter as nvarchar

I got an oracle database, with a NVARCHAR2(2000 CHAR) field, the hbm file I have generated by hibernate reverse engineering is as below

<property name="remarks" type="string">
    <column length="4000" name="REMARKS" />
</property>

While update this file in database, I found it bind to varchar instead of nvarchar

org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [VARCHAR]

If I enter 2000 Chinese characters, it will exceed its field length.
How can I make it bind to nvarchar instead?


Update
It is due to Oracle Database I am using.
Reference - "By default, oracle.jdbc.OraclePreparedStatement treats all columns as CHAR."


Solution

Turn out I add defaultNChar to JNDI connection property

 <connection-property name="defaultNChar">
     true
 </connection-property>

Upvotes: 0

Views: 2542

Answers (2)

Red Bit
Red Bit

Reputation: 485

It is due to Oracle Database I am using.
Reference - "By default, oracle.jdbc.OraclePreparedStatement treats all columns as CHAR."

Turn out I add defaultNChar to JNDI connection property

 <connection-property name="defaultNChar">
    true
 </connection-property>

Upvotes: 0

Larry.Z
Larry.Z

Reputation: 3724

Try to modify hbm file like this

<property name="remarks" type="string">
    <column name="REMARKS" sql-type="nvarchar(2000)"/>
</property>

Upvotes: 0

Related Questions