Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How mapping xml column Hibernate from DB SQL Server

 
Alfredo Hidalgo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm new here, maybe this topic shouldn't be here, but I don't know where ask and I need solve this question.

I have a table in SQL Server and I need mapping, but it has a xml column, then I don't know how do that.

My table:

TableXXX
ID (PK, int, not null)
Name (nvarchar(200), not null)
Data (XML, not null)


In HBM.XML:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="Test.dbo"
namespace="Project.Domain.Test" assembly="Project.Domain.Test">
<class name="TableXXX" table="TableXXX">
<id name="ID" type="System.Int32" column="ID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="Name" type="System.String"/>
<property name="Data" column="Data" type=??? />
</class>
</hibernate-mapping>


In C# definition of table:
using System;
using System.Xml;

namespace Project.Domain.Test
{
public class TableXXX
{
public virtual Int32 ID { get; set; }
public virtual String Name { get; set; }
public virtual ??? Data { get; set; } }
}
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the future please UseCodeTags rather than bold and color for formatting code and configuration.

You will need to define your own UserType. Below is an example of this for Oracles XmlType column. Perhaps one is out there somewhere for SQL server already otherwise this serves as an example of how to do the same.

http://solecjj.blogspot.com/2011/02/hibernate-with-oracle-xmltype.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic