使用Oracle 10g时,Hibernate对浮点列进行模式验证的已知问题的最佳解决方法是什么? [英] What are the best workarounds for known problems with Hibernate's schema validation of floating point columns when using Oracle 10g?
问题描述
我有几个带有双字段的Java类,我通过Hibernate持久化。例如,我有
@Entity
公共类节点...
私有双重价值;
当Hibernate的 org.hibernate.dialect.Oracle10gDialect
为Node表创建DDL,它将值字段映射为双精度类型。
create table MDB。节点(...值双精度不为空,...
看来在Oracle中, double precision是float的别名,所以当我尝试使用 org.hibernate.cfg.AnnotationConfiguration.validateSchema()
方法验证数据库模式时, Oracle似乎将value列描述为float,这会导致Hibernate抛出以下异常:
org.hibernate.HibernateException :列值为DBO.ACL_RULE中错误的列类型找到:float,expected:double precision
A在Hibernate的JIRA数据库中列出了非常类似的问题,如 HHH-1 961个。我希望避免做任何会破坏MySql,Postgres和Sql Server的支持,因此扩展 Oracle10gDialect
似乎是 HHH-1961 。但是延长方言是我以前从未做过的事情,我担心可能会有一些令人讨厌的问题。这个问题的最佳解决方法是什么,不会破坏我们与MySql,Postgres和Sql Server的兼容性?
这是模式验证器的已知限制,请检查 HHH-2315 。所以你在这里有三个选项(实际上是四个,但我想不需要停用验证)。要么: 使用 hibernate.mapping.Table.validateColumns(方言方言,映射映射,TableMetadata tableInfo)为这个特殊情况添加一个特殊条件 - 这不是一个明亮的选项。 扩展 后面的选项看起来很安全,但需要进行一些测试以确定它是否不引入任何回归。我没有看Oracle的JDBC驱动程序代码,所以我不能说 I have several Java classes with double fields that I am persisting via Hibernate. For example, I have When Hibernate's It would appear that in Oracle, "double precision" is an alias for "float". So, when I try to verify the database schema using the A very similar problem is listed in Hibernate's JIRA database as HHH-1961. I'd like to avoid doing anything that will break MySql, Postgres, and Sql Server support so extending the This is a known limitation of the schema validator, check HHH-2315. So you have three options here (actually four but I guess that deactivating validation is not wanted). Either: Use a Patch Extends the The later option seems safe but will require some testing to see if it doesn't introduce any regression. I didn't look at Oracle's JDBC driver code, so I can't say how 这篇关于使用Oracle 10g时,Hibernate对浮点列进行模式验证的已知问题的最佳解决方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
float
而不是 double 在Java级别 - 这可能不是一个选项。
org.hibernate.dialect.Oracle10gDialect
使其使用 float
为SQL类型 DOUBLE
public class MyOracle10gDialect extends Oracle10gDialect {
public MyOracle10gDialect(){
super();
protected void registerNumericTypeMappings(){
super.registerNumericTypeMappings();
registerColumnType(Types.DOUBLE,float);
code $
$ b $ p float
和双精度
在司机级别。@Entity
public class Node ...
private double value;
org.hibernate.dialect.Oracle10gDialect
creates the DDL for the Node table, it maps the value field to a "double precision" type.create table MDB.Node (... value double precision not null, ...
org.hibernate.cfg.AnnotationConfiguration.validateSchema()
method, Oracle appears to describe the value column as a "float". This causes Hibernate to throw the following Exception org.hibernate.HibernateException: Wrong column type in DBO.ACL_RULE for column value. Found: float, expected: double precision
Oracle10gDialect
appears to be the most promising of the workarounds mentioned in HHH-1961. But extending a Dialect is something I've never done before and I'm afraid there may be some nasty gotchas. What is the best workaround for this problem that won't break our compatibility with MySql, Postgres, and Sql Server?
float
instead of a double
at the Java level - this might not be an option though.org.hibernate.mapping.Table.validateColumns(Dialect dialect, Mapping mapping, TableMetadata tableInfo)
to add a special condition for this particular case - this isn't really a light option.org.hibernate.dialect.Oracle10gDialect
to make it use float
for the SQL type DOUBLE
public class MyOracle10gDialect extends Oracle10gDialect {
public MyOracle10gDialect() {
super();
}
protected void registerNumericTypeMappings() {
super.registerNumericTypeMappings();
registerColumnType( Types.DOUBLE, "float" );
}
}
float
and double precision
differ at the driver level.