问题描述
我有一个oracle表,它包含几个列的char(n)类型。我使用hibernate工具创建实体对象,并在String中使用此工具映射char类型。
但是,当我部署我的应用程序时,出现错误,因为Hibernate等待varchar2类型并不是字符类型:
ARBOR.CMF中列CHG_WHO的列类型错误。发现:char,expected:varchar2(30 char)
必须使用什么样的java类型来映射char(n)在一个实体中的类型?
感谢。
基本上你需要让你的hibernate配置更加具体化,因为它假设一个默认的String映射到varchar2(30 )。
您可以尝试使用@Column(length = N)的数据库不可知注释(其中N是数据库中列的实际长度)。如果这不起作用,请尝试使用@Column(columnDefinition =char)方法。
I have a oracle table which contains char(n) type for several columns. I use hibernate tools to create entities objets and this tool map char type in String.
But when I deploy my application, I get an error because Hibernate wait a varchar2 type and not a char type:
Wrong column type in ARBOR.CMF for column CHG_WHO. Found: char, expected: varchar2(30 char)
What kind of java type must I use to map char(n) type in an entity ?
Thanks.
There's some useful information here on this blog entry.
Essentially you need to make your hibernate configuration more specific, as it's assuming a default String mapping to varchar2(30).
You can try using the database-agnostic annotation of @Column(length=N) (where N is the actual length of your column in the database). If that doesn't work, try using the @Column(columnDefinition = "char") approach.
这篇关于Oracle Char类型和Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!