Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!