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.  [ 3 posts ] 
Author Message
 Post subject: Can't load bag of bidirectional many-to-many
PostPosted: Tue Sep 11, 2007 3:10 pm 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
Hibernate version:
1.2 GA

Mapping documents:
ContentItem.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Fcsb.Technology.Hybrid.Core.IContentItem, Fcsb.Technology.Hybrid.Core" table="ContentItem">
      <id name="Id" type="int">
         <generator class="native" />
      </id>
      <discriminator column="Type" type="string" />
      
      <subclass name="Fcsb.Technology.Hybrid.Core.Document, Fcsb.Technology.Hybrid.Core" lazy="true" discriminator-value="DOCUMENT">
         <property name="Title" type="string" />
         <property name="Description" type="string" />
         <property name="Filename" type="string" />
         <property name="PubDate" type="DateTime" />
         <many-to-one name="Owner" class="Fcsb.Technology.Hybrid.Core.HybridUser, Fcsb.Technology.Hybrid.Core" column="UserId" not-null="true" access="field.camelcase-underscore" />
         
         <bag name="Tags" access="field.camelcase-underscore" table="ContentItem_Tag" lazy="true">
            <key>
               <column name="ContentItemId" not-null="true" />
            </key>
            <many-to-many class="Fcsb.Technology.Hybrid.Core.Tag, Fcsb.Technology.Hybrid.Core">
               <column name="TagId" not-null="true" />
            </many-to-many>
         </bag>
      </subclass>
   </class>
</hibernate-mapping>


Tag.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Fcsb.Technology.Hybrid.Core.Tag, Fcsb.Technology.Hybrid.Core">
      <id name="Id" type="int">
         <generator class="native" />
      </id>
      <property name="Name" type="string" />
      <bag name="ContentItems" access="field.camelcase-underscore" inverse="true" table="ContentItem_Tag" lazy="true">
         <key column="TagId" />
         <many-to-many class="Fcsb.Technology.Hybrid.Core.IContentItem, Fcsb.Technology.Hybrid.Core" column="ContentItemId" />
      </bag>
   </class>
</hibernate-mapping>


Name and version of the database you are using:
Sql 2005

Generated SQL during Unit Test:
Code:
NHibernate: INSERT INTO ContentItem (Title, Description, Filename, PubDate, UserId, Type) VALUES (@p0, @p1, @p2, @p3, @p4, 'DOCUMENT'); @p0 = 'title', @p1 = 'description', @p2 = '', @p3 = '9/11/2007 3:11:12 PM', @p4 = '1'
NHibernate: select @@IDENTITY
NHibernate: INSERT INTO Tag (Name) VALUES (@p0); @p0 = 'tag1'
NHibernate: select @@IDENTITY
NHibernate: INSERT INTO Tag (Name) VALUES (@p0); @p0 = 'tag2'
NHibernate: select @@IDENTITY
NHibernate: INSERT INTO ContentItem_Tag (ContentItemId, TagId) VALUES (@p0, @p1); @p0 = '1', @p1 = '1'
NHibernate: INSERT INTO ContentItem_Tag (ContentItemId, TagId) VALUES (@p0, @p1); @p0 = '1', @p1 = '2'



Ok,

Document is an implementor of IContentItem. When I have a an IList<Document> and display all documents, tags are lazyily loaded and show up just find.

When I retrieve a specific Document, and try to navigate the Tags collection it is always empty. But as you can see by the SQL above, the relationship is inserted into the ContentItem_Tag table??

I have been banging my head for the last 4 hours and just can't figure out what is occuring here.

I can't get it to work in any Unit Tests using SqlCE, but it works fine from the listing page that retrieves all documents.

Is there something wrong with my mapping files?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 2:12 pm 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
bump...

this doesn't seem like too difficult of a problem to me? doesn't anyone see something simple im missing?

please? =)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 4:13 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
What does the code for each kind of load look like? What about the logs on loading? The generated SQL? I suspect there may be some kind of proxy/lazy issue related to your use of field-only access for the collections.


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