HibernateException:错误的列类型:x,在Sybase上预期为:y [英] HibernateException: Wrong column type:x, expected: y on Sybase

查看:79
本文介绍了HibernateException:错误的列类型:x,在Sybase上预期为:y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下技术没有太多背景知识,所以我们将不胜感激.如果有不清楚的地方,请随时提出问题.

I don't have much background on the technologies below so any help would be appreciated. Please feel free to ask questions if something's not clear.

我目前正在开发一个迁移项目,其中我们正在更新许多技术,包括:

I'm currently working on a migration project wherein we're updating a number of technologies including:

  1. Sybase -从12.x到15.7
  2. JConnect -从多个版本到7.0.7_SP130
  1. Sybase - from 12.x to 15.7
  2. JConnect - from several versions to 7.0.7_SP130

现在,我们的应用程序已部署到 JBoss 4.x 并使用 Hibernate 3.2.4.sp1 .在旧的DB中,我们有许多看起来像这样的自定义数据类型(对不起,很想将它以表格式放置,但是我不知道如何在这里...):

Now, our apps are deployed on to JBoss 4.x and use Hibernate 3.2.4.sp1. In the old DB, we have a number of custom datatypes that look something like this (sorry, would have loved to put this in table format, but I don't know how to here...) :

  • 自定义数据类型:TYPE1,基本数据类型:图像
  • 自定义数据类型:TYPE2,基本数据类型:tinyint
  • Custom datatype: TYPE1, Base datatype: image
  • Custom datatype: TYPE2, Base datatype: tinyint

DDL中的某些列使用自定义数据类型:

Some columns in our DDL use the custom datatypes:

CREATE TABLE y (
   our_column_name TYPE1,
   ...
);

服务器启动时,出现以下错误消息:

When the server is started up, I get the following error message:

... javax.persistence.PersistenceException: org.hibernate.HibernateException:错误的列类型:our_column_name, 预期:图片

... javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: our_column_name, expected: image

这不是旧设置中发生的情况.请注意,在我们定义的所有自定义数据类型中,只有那些具有 image tinyint 的数据类型才存在问题;其他的被识别并且没有错误.

which is not what happens in the old setup. Do take note that of all the custom datatypes we've defined, only those with image and tinyint have issues; the others are recognized and throw no error.

我们已经在JConnect驱动程序上运行了一个跟踪,看来它正在检索正确的数据类型,这就是为什么我现在专注于HibernateException.我看过几篇类似的文章(发生在不同的数据库上),但是基本上,他们给出了类似的解决方法:

We've run a trace on the JConnect driver and it appears that it's retrieving the correct datatype, which is why I'm now focusing on the HibernateException. I've seen a couple of posts similar to this one (occurring on different DBs), but basically, they gave similar workarounds:

  1. 这一个网站这样的网站,建议我们更改数据库表的列以使用基本数据类型而不是自定义数据类型.为此,我们将 our_column_name 的数据类型更改为image.完成此操作并重新启动服务器后,错误消失了.但是,它没有解释为什么或导致问题的原因.

  1. One site like this one, it's suggested that we alter the DB table's column to use the base datatype instead of the custom datatype. We've done this by changing our_column_name's datatype to image. Once this was done and the server was restarted, the error goes away. However, it does not explain why or what caused the issue.

建议使用JPA注释的@Column(columnDefinition='image').我们也尝试过这种方法,但是它似乎对启动没有任何影响(即仍然发生错误).

This suggested the use of JPA annotations' @Column(columnDefinition='image'). We've tried this as well, but it doesn't seem to have any effect on the startup (i.e. error still occurred).

在与#2相同的链接中,建议扩展SQL方言.但是,我认为这是不可行的-似乎只有2种自定义数据类型(图像和tinyint)导致了我们的问题,所以这可能是过大了.

In the same link as #2, it was suggested that the SQL Dialect be extended. However, I don't think this is feasible - only 2 custom datatypes (image and tinyint) seem to be causing the problems on our end so this may be overkill.

本网站建议从persistence.xml中删除hibernate.hbm2ddl.auto=validate.尚未尝试过此操作,因为我们需要进行验证.

This site suggests the removal of hibernate.hbm2ddl.auto=validate from persistence.xml. Have not tried this as we need the validation to be in place.

改为使用数据类型"LOB"

Use the datatype "LOB" instead

自从这里抛出异常以来,我还尝试检查过Hibernate的代码-org.hibernate.mapping.Table.validateColumns(Table.java:261),这几乎指向以下行:

I've also tried checking out Hibernate's code since the exception was thrown here - org.hibernate.mapping.Table.validateColumns(Table.java:261), which pretty much points to this line:

boolean typesMatch = (col.getSqlType(dialect, mapping).startsWith(columnInfo.getTypeName().toLowerCase())) || (columnInfo.getTypeCode() == col.getSqlTypeCode(mapping));

但是,Hibernate的API文档有点详细信息,因此目前在跟踪此信息时有些困难...

However, Hibernate's API documentation is a little wanting in details so I'm having some difficulty in tracing this at the moment...

关于导致异常的原因的任何想法?如果它在旧版本中可用,是否想知道Hibernate(或Sybase)的哪些变化会导致这种情况?

Any ideas on what's causing the exception? If it's working in the old version, was wondering on what changes in Hibernate (or Sybase for that matter) can cause this?

文档表明Hibernate已针对Sybase 15.7进行了测试,因此我一头雾水在哪里继续寻找.上面的#1是最好的解决方法吗?如果是这样,那么为什么应该使用基本类型而不是自定义数据类型的任何想法(从本质上讲,这将使自定义数据类型无用...)

This document suggests that Hibernate is tested against Sybase 15.7 so I'm at a loss where to continue looking. And would #1 above be the best workaround? If so, any ideas why base types should be used instead of custom datatypes (which would, in essence, render custom datatypes useless...)

再次感谢!

编辑:

尝试了以下内容:

  1. 如果使用@Column(columnDefinition='my_custom_datatype'),则错误消失了.
  2. 如果从persistence.xml中删除了hibernate.hbm2ddl.auto=validate,该错误就会消失.
  1. If @Column(columnDefinition='my_custom_datatype') is used, then the error goes away.
  2. If hibernate.hbm2ddl.auto=validate is removed from persistence.xml, the error goes away.

我真的怀疑这是一个休眠的问题...

I'm really suspecting it's a hibernate issue...

推荐答案

这与

This is similar in nature to this question on SO i.e. typesMatch in the code in my query above will be false because the values being returned by col and columnInfo are different - one is returning the base datatype, the other is returning the custom user type.

因此,要解决该问题,可以采用多种解决方法(我在上面的文章中已经提到过)-

So, to deal with it, a number of workarounds are possible (and I've mentioned it in my post above) -

  1. 如果可以,请删除hibernate.hbm2ddl.auto=validate.
  2. 直接在数据库中更改列数据类型,我认为这是下一个最快的方法.
  3. 在Java类中使用@Column(columnDefinition='my_custom_datatype').
  1. Remove hibernate.hbm2ddl.auto=validate if you can.
  2. Change the column datatypes directly in DB, which I think is the next fastest approach.
  3. Use @Column(columnDefinition='my_custom_datatype') in the Java class.

这篇关于HibernateException:错误的列类型:x,在Sybase上预期为:y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆