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?