【发布时间】:2014-11-02 12:55:41
【问题描述】:
我正在尝试使以下设置正常工作: Wildfly 8.1.0(附带 Hibernate 作为 JPA 实现) Postgres 9.3 数据库
我想将 Java 字符串映射到 postgres 的 xml 类型的列,但我收到错误,即该列的类型为“xml”,而表达式的类型为 varchar。
我发现的大多数(可能)解决方案是针对特定于数据库的 java 类、特定于休眠的解决方法或只是在 Stackoverflow 上未回答的问题。
我想使用定义好的JPA-Methods能够随意切换到Mysql或者SQLServer,甚至不用接触代码就可以用glassfish或者tomcat+openJPA替换Widlfly+hibernate。
但是,在数据库中调整一些东西就可以了。
我当然已经做了一些研究并找到了这篇文章: http://www.pateldenish.com/2013/05/inserting-json-data-into-postgres-using-jdbc-driver.html
所以我尝试为 text 和 varchar 添加隐式转换:
create cast (varchar as xml) without function as implicit;
create cast (text as xml) without function as implicit;
但 postgres 只是说这些演员表已经存在。我通过将随机字符串插入 xml 列来验证这一点,效果很好。
异常仍然发生。
提前感谢您的提示和指导,
比尔门
更新:
我使用 postgres 9.3.1102.jdbc41
语句休眠问题:
[PreparedStatement] setLong(3, 20)
[PreparedStatement] setNull(2, -3)
[PreparedStatement] setNull(1, 12)
[Connection] prepareStatement(insert into testTable (xml, stuff, id) values (?, ?, ?))
fyi:stuff 和 xml 可以为空,ID 是 primaryKey,从序列中正确检索到 20。
【问题讨论】:
标签: hibernate postgresql wildfly