本文介绍了Hibernate与NVARCHAR2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列作为 NVARCHAR2 的表,并且我用hibernate注释来构建我的对象,当我想要插入到DB或从DB获取结果是就像那个???????,
我已经实现了一个自定义方言如下,但它没有工作。

I have table with a column as NVARCHAR2, and I have build my object with hibernate annotations, When i want to insert into DB or fetch from DB the result is something like that "???????",I have implemented a custom Dialect as follows but it did not work.

public class CustomOracleDialect extends Oracle10gDialect{

    public CMSCustomOracleDialect() {
        registerHibernateType( Types.NVARCHAR, Hibernate.STRING.getName() );
        registerColumnType( Types.VARCHAR, "nvarchar2($1)" );
        registerColumnType( Types.CLOB, "nclob" );
        registerColumnType( Types.NCLOB, "nclob" );
    }

}


推荐答案

可能会有点迟,但我刚刚遇到过这个问题,并且我发现可以用

Might be a little late but I have just come across this issue aswell and I found that can annotate your hibernate class with

@Nationalized

@Type(type="org.hibernate.type.StringNVarcharType")

这使得你的元素使用 org.hibernate.type.StringNVarcharType 而不是VarChar类型的字符串

which makes your element use org.hibernate.type.StringNVarcharType instead of the VarChar type string

在4.1.10及更高版本中进入休眠状态。因此,它正确地使用了 NVarChar2 类型,否则它将默认返回到VarChar2,然后丢失您的国际字符。

which was introduced into hibernate in release 4.1.10 and above. So that it correctly uses the NVarChar2 type or else it will default back to VarChar2 which then looses your international characters.

解决这个问题的Hibernate Jira:

Hibernate Jira where this was resolved: https://hibernate.atlassian.net/browse/HHH-5869

和Jboss-Hibernate文档:

And Jboss-Hibernate Documentation:https://docs.jboss.org/hibernate/orm/4.3/devguide/en-US/html/ch08.html#value-national-character-types

这篇关于Hibernate与NVARCHAR2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 05:24