JPA支持XML数据类型列 [英] JPA support for XML datatype columns

查看:129
本文介绍了JPA支持XML数据类型列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们开始的一个新项目(在Hibernate 3之上使用JPA 2),我们需要能够存储XML文档,然后在以后查询其内容和结构。我们希望支持的数据库是DB2,Oracle和SQLServer。我知道所有三家数据库供应商都支持原生XML查询(使用SQL和XQuery类语句),但是在那里Hibernate中对此有何直接支持?换句话说,我可以编写一组hibernate数据访问代码,它们可以使用Hibernate / JPA的内置功能以非自动方式查询所有3种数据库类型,还是需要为每种数据库类型编写特定查询?



我明白我可以将列定义为@Lob列,然后读取所有记录,解析和检查,但我希望利用数据库引擎的强大功能,而不必执行它自己。

仅供参考,我们一次只能使用一种数据库风格,只是我们希望能够支持所有3个应用程序。 / p>

感谢史蒂夫

解决方案

JPA不提供对这些的特定支持超过 Lob 的专有类型。对于更高级的支持,我想你必须实现一些Hibernate自定义用户类型。以下文件可能会给你一些想法。





当然,它们将与数据库相关,并且会减少代码

关于查询,AFAIK在HQL语句的 WHERE 子句中调用的任何函数,并且isn Hibernate已知的数据按原样传递给数据库。所以你可以利用特定的功能。但是,这又会使查询数据库具体化。也许可以考虑为特定的部署使用 orm.xml 映射。


For a new project we are starting (which uses JPA 2 on top of Hibernate 3) we need to be able to store XML documents and then query on their content and structure at a later date. The databases we would like to support are DB2, Oracle and SQLServer.

I know all three DB vendors support native XML querying (using SQL and XQuery like statements) but is there any direct support within Hibernate for this? In other words, can I write one set of hibernate data access code which queries all 3 database types agnostically using a built-in feature of Hibernate/JPA or would I need to code specific queries for each DB type?

I appreciate that I could define the column as a @Lob column and then read all the records, parse and inspect but I was hoping to leverage the power of the DB engine rather than having to do it myself.

For reference we would only ever be using one DB flavour at a time, it's just that we want to be able to support all 3 should we need to.

Thanks Steve

解决方案

JPA doesn't offer specific support for these proprietary types beyond Lob. For more advanced support, I guess you'll have to implement some Hibernate custom user types. The following documents might give you some ideas.

Of course, they will be database specific and will make the code less portable.

Regarding querying, AFAIK any function that is called in the WHERE clause of an HQL statement and that isn't known to Hibernate is passed as is to the database. So you could leverage specific functions. But again, this will make the queries database specific. Maybe consider using orm.xml mappings for specific deployments.

这篇关于JPA支持XML数据类型列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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