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: Unable to persist an IList using <list> mapping, bug?
PostPosted: Tue Sep 05, 2006 8:42 am 
Newbie

Joined: Wed Aug 16, 2006 12:56 pm
Posts: 4
Hi,

I am having problems peristing an IList using the <list> mapping.

I am pretty sure my mappings are correct as I have already got an IDictionary persisting using <map>, so I have experience how collection mappings are defined.

I have used the debugger to step through the Nhibernate-1.0.2.0 code and the problem seems to be in

Code:
NHibernate.Impl.OnUpdateVisitor


in the method

Code:
protected override object ProcessCollection(object collection, PersistentCollectionType type)


line 42

Code:
if( collection is PersistentCollection )


Seems my IList collection should be getting replaced with the equivalent PersistentCollection type.

Originally I defined my collection as a
Code:
System.Collections.Generic.List<T>
, which I thought was the problem,
but then I tried redefining it as a
Code:
System.Collections.Arraylist
, which didn't work either.

I think it is a bug, does anyone know of a work around?

Thanks, Neil


Top
 Profile  
 
 Post subject: Re: Unable to persist an IList using <list> mapping, b
PostPosted: Tue Sep 05, 2006 8:53 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
neil_janabi wrote:
Seems my IList collection should be getting replaced with the equivalent PersistentCollection type.

Originally I defined my collection as a
Code:
System.Collections.Generic.List<T>
, which I thought was the problem,


Your class proeprty and field must be of type IList<t>, not List<T>

Code:
private System.Collections.Generic.IList<T> m_MyCollection;

public System.Collections.Generic.IList<T> MyCollection
{
  get {return m_MyCollection; }
}


Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 9:24 am 
Newbie

Joined: Wed Aug 16, 2006 12:56 pm
Posts: 4
I am still using version 1.0.2.0 which I didn't think supported generics.

Anyway I tried persisting my list as

Code:
private List<UserPortfolioExchangeProduct> _userPortfolioExchangeProducts;

private IList PersistedUserPortfolioExchangeProducts
{
    get
    {
        IList list = new ArrayList(_userPortfolioExchangeProducts);
        return list;
    }
}


Which also returns false in

Code:
NHibernate.Impl.OnUpdateVisitor


method

Code:
protected override object ProcessCollection(object collection, PersistentCollectionType type)


line 42

Code:
if( collection is PersistentCollection )


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 9:29 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
neil_janabi wrote:
I am still using version 1.0.2.0 which I didn't think supported generics.


In this case, both property and field in class must be of IList type. I.e.
Code:
private System.Collections.IList m_MyCollection = new ArrayList();

public System.Collections.IList MyCollection
{
  get {return m_MyCollection; }
}

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 9:45 am 
Newbie

Joined: Wed Aug 16, 2006 12:56 pm
Posts: 4
Sorry I ommited the setter in my last sample snippet, as in my code

Code:
        private IList PersistedUserPortfolioExchangeProducts
        {
            get
            {
                IList list = new ArrayList(_userPortfolioExchangeProducts);
                return list;
            }
            set
            {
                // TODO
            }
        }


So the problem still exists

I did a similar thing with a generic dictionary cast to an IDictionary mapped to a <map> which worked OK, snippet

Code:
private Dictionary<PricingUnit, PricingUnitsConversion> _pricingUnitsConversions;

    private IDictionary PricingUnitsConversions
    {
        get
        {
            return _pricingUnitsConversions;
        }
        set
        {
           _pricingUnitsConversions =
                new Dictionary<PricingUnit, PricingUnitsConversion>(value.Count);

            foreach (PricingUnit pricingUnit in value.Keys)
                _pricingUnitsConversions[pricingUnit] =
                    (PricingUnitsConversion)value[pricingUnit];
        }
    }


Still think the problem is in the Nhibernate code as both List<T> and ArrayList implement System.Collections.IList


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 9:58 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
neil_janabi wrote:
Sorry I ommited the setter in my last sample snippet, as in my code

Code:
        private IList PersistedUserPortfolioExchangeProducts
        {
            get
            {
                IList list = new ArrayList(_userPortfolioExchangeProducts);
                return list;
            }
            set
            {
                // TODO
            }
        }


So the problem still exists

I did a similar thing with a generic dictionary cast to an IDictionary mapped to a <map> which worked OK, snippet

Code:
private Dictionary<PricingUnit, PricingUnitsConversion> _pricingUnitsConversions;

    private IDictionary PricingUnitsConversions
    {
        get
        {
            return _pricingUnitsConversions;
        }
        set
        {
           _pricingUnitsConversions =
                new Dictionary<PricingUnit, PricingUnitsConversion>(value.Count);

            foreach (PricingUnit pricingUnit in value.Keys)
                _pricingUnitsConversions[pricingUnit] =
                    (PricingUnitsConversion)value[pricingUnit];
        }
    }


Still think the problem is in the Nhibernate code as both List<T> and ArrayList implement System.Collections.IList


First of all, this setter is not very perfomance-wise, as NHibernate is not able to track the changes made to collection. Second, it is not adviceable to have setters for collection proeprties (as per MS guidelines)

But going back to Your problem with IList: what is the access strategy for collection? If it involves fields (Like nosetter-smth), try changing. Otherwise, post actual code and mapping (whole map file) for the problematic class.

Gert

_________________
If a reply helps You, rate it!


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.