Hibernate 3.3.2GA不正确地从PostgreSQL 9.0加载bytea数据,所有的类型映射都是正确的 [英] Hibernate 3.3.2GA improperly loads bytea data from PostgreSQL 9.0 and all type mappings are correct

查看:316
本文介绍了Hibernate 3.3.2GA不正确地从PostgreSQL 9.0加载bytea数据,所有的类型映射都是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能会将bytea列映射为Hibernate类型的二进制文件。在java中,bytea数据适当地表示为byte []。

设置数据时,它会正确显示在PostreSQL 9.0数据库中。



例如:

  set([1,2,0,1,255,0 ])

在普通SQL查询输出中显示为:

  \x010201ff00 

当Hibernate调用你的java set()例程加载数据,数据不正确。除第一个字节以外的所有字节都被更改为字节值的ASCII表示。断点在set()函数处,并观察Hibernate的调用:

  set([1,50,48,49,102, 
$ / code>

等价:

 set([1,'2','0','1','f,'f','0'])

PostgreSQL 9.0已将其默认字节输出从'escape'更改为'hex'。这会混淆(至少)9.0版本以前的hibernate。



解决方法是编辑postgresql.conf文件并将bytea_output的设置从hex以逃生,恢复旧的输出格式。重新启动您的服务器。

  ... 
#vacuum_freeze_min_age = 50000000
#vacuum_freeze_table_age = 150000000
bytea_output ='escape'#十六进制,转义转义需要通过HIBERNATE 3.3.2GA
#xmlbinary ='base64'
#xmloption ='content'
...

您的sql查询数据现在也将以更传统的八进制形式显示:

  \001\002\000\001\377\000 

由于十六进制比较容易阅读,任何人都知道如何配置Hibernate 3.3.2GA来理解十六进制格式?

解决方案

问题不在于Hibernate本身,而在于需要解码这些东西的PostgreSQL JDBC驱动程序。这是一个已知的问题,例如Perl中的DBD :: Pg也是如此。



这个问题在去年5月的PostgreSQL JDBC驱动程序中得到了修复,所以你应该能够简单地升级。请参阅: http://jdbc.postgresql.org/changes.html#version_9.0 -dev800


You may have a bytea column mapped as Hibernate type binary. In java, the bytea data are appropriately represented as byte[].

When you set the data, it appears in your PostreSQL 9.0 database correctly.

For example:

            set( [ 1, 2, 0, 1, 255, 0 ] )

Shows in a normal SQL query output as as:

             \x010201ff00

When Hibernate calls your java set() routine to load the data, the data are incorrect. All but the first byte are changed to the ASCII representation of the byte value. Breakpoint at the set() function and observe Hibernate calling with:

           set( [ 1, 50, 48, 49, 102, 102, 48 ] )

equivalently:

           set( [ 1, '2', '0', '1', 'f, 'f', '0' ] )

PostgreSQL 9.0 has changed its default bytea output from 'escape' to 'hex'. This confuses (at least) the pre-9.0 versions of hibernate.

To resolve, edit the postgresql.conf file and change the setting for "bytea_output" from "hex" to "escape", restoring the old output format. Restart your server.

...
#vacuum_freeze_min_age = 50000000
#vacuum_freeze_table_age = 150000000
bytea_output = 'escape'         # hex, escape  escape is REQUIRED BY  HIBERNATE 3.3.2GA
#xmlbinary = 'base64'
#xmloption = 'content'
...

Your sql query data will also now display in the more traditional octal form:

\001\002\000\001\377\000

Since hex is easier to read, anyone know how to configure Hibernate 3.3.2GA to understand the hex format?

解决方案

The problem isn't with Hibernate per se, but with the PostgreSQL JDBC driver that needs to decode this stuff. It's a known issue, the same happens with for example DBD::Pg in Perl.

This issue was fixed in the PostgreSQL JDBC driver last May, so you should be able to simply upgrade that. See: http://jdbc.postgresql.org/changes.html#version_9.0-dev800

这篇关于Hibernate 3.3.2GA不正确地从PostgreSQL 9.0加载bytea数据,所有的类型映射都是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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