-->
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: Is NHibernate useless when using webservices?
PostPosted: Wed Mar 01, 2006 11:06 am 
Regular
Regular

Joined: Sun Feb 12, 2006 10:18 pm
Posts: 60
Location: Rosario, Argentina
I'm trying to use NHibernate to persist my clases to the database. In

order to do that, all "set"s must be mapped through a Iesi

collection, so all of my collections are declared as

Iesi.Collections.ISet. i.e.:

Code:
[Serializable]
public class Country
{
    // Property accessors
    virtual public System.Int32 Id
        {
            get { return this.id;}
            set { this.id = value;}
        {
    virtual public System.String Name
   {
            get { return this.name;}
            set { this.nombre = value;}
        }
    virtual public Iesi.Collections.ISet States
        {
            get { return this.states;}
            set { this.states = value;}
        }
   
   
    // Fields   
    private System.Int32 id;
    private System.String name;
    private Iesi.Collections.ISet states = new

Iesi.Collections.HashedSet();
   
   
    // Constructors
    /// <summary>default constructor </summary>
    public Pais()
    {}

    /// <summary>full constructor </summary>
    public Pais(ref System.Int32 id, System.String name,

Iesi.Collections.ISet states)
    {
    this.id = id;
    this.name = name;
    this.states = states;
    }
}


As it's going to be a web site that uses this clases, I wanted to

serve them as web services, using an SOA architecture. I tested the

NHibernate mapping files and everything with a windows form, and it

worked fine, so I created the web service that would serve my website

(and any website that might want to use it) and added a getCountry

web method. To my surprise, when I tryed to test it, I found out that

, despite the project compiled perfectly, I got an error message

saying: "You must implement a default accessor on Iesi.Collections.ISet because it inherits from ICollection.". I did some research, and found out that the interface Iesi.Collections.ISet cannot be serialized, and that's what causes the error... Unfortunately, I also noticed that everybody allways used some workaround to solve this problem, but it's allways a patch and never a solution... so, my question is, did I make a mistake choosing NHibernate? Applications are more and more using web services to interact with other applications, so is the NHibernate team (or the Iesi team) going to solve this problem? Is there an easy solution to be able to use web services that doesn't include "cheating" nor hours of refactoring?

Alex.


Top
 Profile  
 
 Post subject: Re: Is NHibernate useless when using webservices?
PostPosted: Wed Mar 01, 2006 11:52 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
AleBrozzo wrote:
saying: "You must implement a default accessor on Iesi.Collections.ISet because it inherits from ICollection.". I did some research, and found out that the interface Iesi.Collections.ISet cannot be serialized, and that's what causes the error... Unfortunately, I also noticed that everybody allways used some workaround to solve this problem, but it's allways a patch and never a solution... so, my question is, did I make a mistake choosing NHibernate? Applications are more and more using web services to interact with other applications, so is the NHibernate team (or the Iesi team) going to solve this problem? Is there an easy solution to be able to use web services that doesn't include "cheating" nor hours of refactoring?


You should create some test cases using plain objects to see what can be sent over trought web servciers and what can not. AFAIK, big interrelated object graphs (with back-links) are always quite a big challange for a web service. All this is not related to NHibernate but a basic structure how SOAP messages are formed.

Anyway, I have seen no solution of sending data over web services so that it would not require cheating nor hours of refactoring. If You find some, let me know - I would be glad to hear. And we might be able to figure out how to make it doable with NHibernate.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 12:08 pm 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I agree completely with Gert.
At this point I do it myself: serializing to normal arraylists. (or generic lists).

I would very much like for the nhibernate team to give more hooks in the nh-collections. When returning from the client with data to be saved/inserted/deleted, I wish I could create the bag myself.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 5:44 pm 
Regular
Regular

Joined: Sun Feb 12, 2006 10:18 pm
Posts: 60
Location: Rosario, Argentina
The error is thrown only if I have a property of type Iesi.Collections.ISet . If I remove or hide this property, I don't get the "You must implement a default accessor on Iesi.Collections.ISet because it inherits from ICollection." error. So I changed my "Country" class so it looks like this (I saw it somewhere else in the forum):

Code:
        [System.Xml.Serialization.XmlIgnore]
        virtual public Iesi.Collections.ISet States
        {
            get
            {
                return this.states;
            }
         
            set
            {
                this.states = value;
            }
         
        }


which ignores this property when serializing, so it doesn't raise the error. Then I added

Code:
        [System.Xml.Serialization.XmlElement("States")]
        virtual public System.Collections.ArrayList StatesList
        {
            get
            {
                return (new System.Collections.ArrayList(this.states));
            }
            set
            {
                this.states.Clear();
                this.states.AddAll(value);
            }
        }


This "overrides" the States property, and returns an ArrayList, which is serializable. So this works, and does not raise an exception. Buuuut (there's always a but) it does raise a mapping exception. My mind is melting at this point...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 1:54 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
If StatesList is not mapped, why should it raise mapping exception? Knowing exception details might be helpful.


Top
 Profile  
 
 Post subject: Re: Is NHibernate useless when using webservices?
PostPosted: Sat Mar 04, 2006 7:05 am 
Beginner
Beginner

Joined: Fri Nov 11, 2005 1:04 pm
Posts: 22
AleBrozzo wrote:
I'm trying to use NHibernate to persist my clases to the database. In

order to do that, all "set"s must be mapped through a Iesi

collection, so all of my collections are declared as

Iesi.Collections.ISet. i.e.:

Code:
[Serializable]
public class Country
{
    // Property accessors
    virtual public System.Int32 Id
        {
            get { return this.id;}
            set { this.id = value;}
        {
    virtual public System.String Name
   {
            get { return this.name;}
            set { this.nombre = value;}
        }
    virtual public Iesi.Collections.ISet States
        {
            get { return this.states;}
            set { this.states = value;}
        }
   
   
    // Fields   
    private System.Int32 id;
    private System.String name;
    private Iesi.Collections.ISet states = new

Iesi.Collections.HashedSet();
   
   
    // Constructors
    /// <summary>default constructor </summary>
    public Pais()
    {}

    /// <summary>full constructor </summary>
    public Pais(ref System.Int32 id, System.String name,

Iesi.Collections.ISet states)
    {
    this.id = id;
    this.name = name;
    this.states = states;
    }
}


As it's going to be a web site that uses this clases, I wanted to

serve them as web services, using an SOA architecture. I tested the

NHibernate mapping files and everything with a windows form, and it

worked fine, so I created the web service that would serve my website

(and any website that might want to use it) and added a getCountry

web method. To my surprise, when I tryed to test it, I found out that

, despite the project compiled perfectly, I got an error message

saying: "You must implement a default accessor on Iesi.Collections.ISet because it inherits from ICollection.". I did some research, and found out that the interface Iesi.Collections.ISet cannot be serialized, and that's what causes the error... Unfortunately, I also noticed that everybody allways used some workaround to solve this problem, but it's allways a patch and never a solution... so, my question is, did I make a mistake choosing NHibernate? Applications are more and more using web services to interact with other applications, so is the NHibernate team (or the Iesi team) going to solve this problem? Is there an easy solution to be able to use web services that doesn't include "cheating" nor hours of refactoring?

Alex.


Two things to note. First, you should declare your collections as generic ICollection objects. If NHibernate uses a different collections library in a future release you would have to search and replace all the code that declares your collections as Iesi.ISet.

Second, just because you are developing a web site does not predicate the use of web services. You can use NHibernate objects directly from within your web app. Web Services should be reserved (in my humble opinion) for external and cross platform communications(i.e. Java - .Net and even then there are better alternatives). I'd definitely steer clear of webservices if you ever intend to use generics in your software. They are not supported...period.


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.