-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Mapping XmlDocument to SQL Server 2005 Xml Column
PostPosted: Thu Jul 12, 2007 2:09 pm 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
I have been working with the new Xml column type in SQL Server 2005 and was wondering if anyone has figured out a good way to map a property of type XmlDocument to the Xml column type.

Is it possible to have a property of the XmlDocument type or do I need to map using a different type? Also, how would I define the DB col type in the mapping file? I am not sure how to proceed here? I want to use the Xml column type because it offers some very good methods to query the xml data.

I appreciate any suggestions!

Kevin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 2:23 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I'm not sure this feature was already existing when NHibernate was created from the Hibernate 2.x version. But if so, I guess you should have a look at some UserType implementation.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 3:37 pm 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
I am only somewhat familiar with custom user types for NHibernate. I am a little confused as to which side of the coin a user type helps with. For example, let's say I have the following class...

Code:
public class UserAccount
{
    private int _id;
    private System.Xml.XmlDocument _accountData;

    public UserAccount() {}

    public int ID
    {
        get {return _id;}
        set {_id = value;}
    }

    public System.Xml.XmlDocument AccountData
    {
        get {return _accountData;}
        set {_accountData = value;}
    }
}


OK... I also have the following DB table...

Code:
ID int
AccountData xml


where xml is the new Sql Server 2005 xml data/column type.

Now, the class System.Xml.XmlDocument actually has a property called OuterXml that returns the string representation of the XML document. This is the value that I actually want to store in the AccountData column in the database. And, when I retrieve the data from the database, I need to reconstitute the System.Xml.XmlDocument using a LoadXml method, which accepts a string representing the XML.

Maybe this is not the best way to go about it, but the fact remains that if I were not worrying about the persistence of this class, I would want to use the System.Xml.XmlDocument to store the account data because it gives me what I need from a progamming point of view. So, now, I just want to persist that property some how.

Also, I would like to use the xml data type in the DB because it provides some great ways to actually select and filter based on data buried in the xml.

Can this be done using user types? In the examples of user types that I have seen, they are usually mapping some class like MonetaryAmount to multiple columns in the DB that have "standard" data types like decimal or varchar.

Anyway, this is just a little more info and background. Thanks!

Kevin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 3:45 pm 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
UPDATE TO LAST POST...

Actually, I thought of a way to simplify this question. How would I go about simple mapping a string value to the new SQL Server 2005 xml column/data type?

It is easy enough to store my XML in a string, but I want to make sure it gets persisted into the xml column/data type in SQL Server 2005. If this is even possible, then I can modify my object to store the XML data as a string and create my System.Xml.XmlDocument objects as needed to work with the XML.

Kevin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 9:14 am 
Newbie

Joined: Tue Jul 24, 2007 8:56 am
Posts: 2
have you found any solution?
Thanks in advance

Simone


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 11:10 am 
Beginner
Beginner

Joined: Mon Nov 07, 2005 11:06 pm
Posts: 28
No, I have not figured this out yet, although I have not been able to spend much time on it lately. I can't be the only one who has run into this issue. Perhaps I need to post the question again phrased a little differently. I think I will do that.

Kevin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.