This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes How mapping xml column Hibernate from DB SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How mapping xml column Hibernate from DB SQL Server" Watch "How mapping xml column Hibernate from DB SQL Server" New topic

How mapping xml column Hibernate from DB SQL Server

Alfredo Hidalgo

Joined: Aug 31, 2012
Posts: 1
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:

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

<?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" />
<property name="Name" column="Name" type="System.String"/>
<property name="Data" column="Data" type=??? />

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

Joined: Mar 07, 2010
Posts: 1682

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.

[How To Ask Questions][Read before you PM me]
I agree. Here's the link:
subject: How mapping xml column Hibernate from DB SQL Server
It's not a secret anymore!