开发者

Can I map a SQLServer XML column to a String in Java using JPA?

I am using playframework with a legacy SQL Server 2008 database that has data stored in XML columns. I would like to be able to access the XML from the java object as a String. I tried simply declaring the column as a String on the java object but it is not being populated. I have tried using the Microsoft SQL Server JDBC driver and also the jTDS driver. I am using Hibernate as the JPA provider but could switch to another provider if that would help.

Is there a way to map the XML column to a String property on the object? Do I need to write a Hibernate UserType? Or should I be using a lower-leve开发者_如何学JAVAl API to achieve this?


Hibernate UserType sound correct. But I fear you need to use then a custom type, so define your column as XMLColumn where XMLColumn holds your data.


The String is being mapped after all! The Hibernate mapping between XML and String is working as expected. It turns out that some incorrect assumptions about the structure of the XML meant that the target node was not being correctly extracted, and the logging level was not set to DEBUG so the raw XML was not visible. A lesson in checking for the obvious before assuming the worst.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜