1

I have this in my entity:

public virtual Iesi.Collections.Generic.ISet<long> Blas { get; set; }

and this for my mapping:

mapping.HasMany(x => x.Blas).AsSet().Element("Value", m => m.Type<long>()); 

This creates the relevant tables and I add data like this:

X.Blas = new Iesi.Collections.Generic.HashedSet<long>();
X.Blas.Add(some_long);

This adds values to the object but the values in Blas are never persisted (everything else of X is).

Can anyone see anything wrong?

Thanks.

Christian

1
  • I tried ICollection as well. Still the data is not persisted. Commented Aug 19, 2011 at 7:52

3 Answers 3

2

if X is loaded through a session then blas is initialized with a changetracking collection. So dont overwrite it. Try X.Blas.Clear(); instead of X.Blas = new Iesi.Collections.Generic.HashedSet<long>();

Sign up to request clarification or add additional context in comments.

Comments

1

Try adding a cascade setting.

mapping.HasMany(x => x.Blas).AsSet()
       .Element("Value", m => m.Type<long>())
       .Cascade.AllDeleteOrphan();

Also you should just be able to use ICollection and a regular Hashset instead of Iesi. Provided you're using at least version 3 (it might work with 2.1.2 or higher as well)

5 Comments

Thanks. Unfort. the values in Blas are still not persisted (and Blas def. contains some)!
Hmm, is the session being flushed, are you by chance rolling back a transaction. Enabling cascading should be all that is required.
no exception. no rollback. yes i flush the session like this: NHibernateSession.Current.Flush(); NHibernateSession.Current.Clear();
I have to add that the parent object contains Blas and I add data to the child (the class that inherits). However, I don't think that should make any difference.
I don't think that lists of elements need cascades, because the are value objects and can't be persisted separately. Cascading is implicit.
0

You should follow proper object oriented encapsulation to avoid problems like this, an example in my post here: How do I map a collection accessed through a read only property?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.