-->
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.  [ 9 posts ] 
Author Message
 Post subject: Collection-Type System.Collections.Generic
PostPosted: Wed May 09, 2007 6:10 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Hello,

I want to make sure that Hibernate is using the System.Collections.Generic.List<Element> because I'm serializing the info across the wire, etc.

Anyway, I thought I could use the collection-type attribute to achieve this. But I think I'm messing up my mapping somehow.

Here is what I have:

<bag name="Elements"
table="SomeTable"
collection-type="System.Collections.Generic.List`1[[Namespace.Element,Namespace]],System.Collections.Generic"
cascade="all-delete-orphan"
generic="true"
fetch="join"
inverse="true"
lazy="false">
<key column="key"/>
<many-to-many column="id" class="Namespace.Note, Namespace"/>
</bag>

Sorry I had to change the table name, etc. But please note the mapping works fine if I remove collection type.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 7:08 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
System.Collections.Generic is in the System assembly

System.Collections.Generic.List`1[[Namespace.Element,Namespace]],System

What's the error you're getting?

Also, bag uses IList, so I don't know if you're especially gaining anything by specifying List explicitly


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 7:46 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
That was a nice catch, but I'm still getting the same problem.

You know, I'm getting a generic error: telling me that it can't parse my mapping file.

"Could not compile the mapping document: Namespace.Element.hbm.xml"

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 5:08 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
OK, I had a problem in my mapping I changed it assembly to mscorlib.

Now I get a different exception:

{"Custom type does not implement UserCollectionType: System.Collections.Generic.List`1[[HibernateTest.Element, HibernateTest.MeetingDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"}

Does this mean that hibernate cannot give me a List<T>? It will only give me types that implmement a bunch of nhibernate interfaces?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 12, 2007 10:07 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Hello,

could someone please tell me if what I'm doing is possible, but I'm making a syntax error.

Or what I'm doing is not possible. ;-)

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 1:08 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
No, what you are doing is not possible.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 3:13 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Thanks sergey!


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 5:59 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 4:18 am
Posts: 51
Location: Belarus, Gomel
Hi h1!

AFAIK, there is no way to get pure List<SomeClass> from NHibernate – only PersistentGenericBag<SomeClass> or an instance of another NHibernate aware collection (PersistentGeneric***<SomeClass> are built-in ones). You may even create your own collection (sample is in "\src\NHibernate.Test\UserCollection" – it is for non-generic collection, but it is not so hard to make it generic). The real problem is that you have to define “special” collection – one that will implement IPersistentCollection interface – to make NHibernate work. Another option is to use one of the built-in classes (PersistentGeneric***) but it is really unreasonable as you’ll get all the same stuff you have with built-in collections.
collection-type attribute must point to special helper class (it is even not a collection class at all!) that will tell NHibernate how it can make use of your own collection classes (either just one “pure” collection, or both of them “pure” collection and “persistent” collection.
I suppose it may be handy to “extend” built-in types (for example to implement IBindingList interface in persistent collection and have ListChanged event there), but not to “shrink” these classes to simple plain List<SomeClass>. BTW maybe you can extend collection to add “smart” serialization capabilities to it (serialize just what you need, excluding all the NHibernate internal stuff) – but I suppose it is easier to do outside of NHibernate.

2 Sergey
Maybe I’m missing something obvious, but do I have to implement my own PersistentGenericBag class (probably a BindingList<T> descendant, or a kind of wrapper?) to have IBindingList capabilities in persistent collections. I tried to wrap NHibernate collection into BindingList<T> in my class property setter, but it force NHibernate to retrieve all the collection – not a behaviour I want to have. Is it possible in principle to have “lazy” collection, which will implement IBindingList interface?

_________________
WBR, Igor


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 2:54 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Since it's BindingList that's forcing NHibernate to load the collection, there isn't much NHibernate could do about that. So yes, you will have to write your own IPersistentCollection implementation.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.