I've gone through the documentation and the sample code, and just haven't been able to figure out the problem with my mapping file. Any help would be appreciated.
Hibernate version: 2.0.1.4000
Mapping documents:
Code:
<class name="ProviderTitle" table="ProviderTitle" lazy="true">
<id name="ProviderTitleId" column="providerTitleID" type="Guid">
<generator class="guid.comb" />
</id>
<one-to-one name="ProviderTitleDetail"
class="EBSCO.DDP.TitleRepository.Core.Entity.ProviderTitleDetail,TitleRepository.Core"
cascade="all"
constrained="true"
property-ref="ProviderTitle" />
</class>
<class name="ProviderTitleDetail" table="ProviderTitleDetail" lazy="true">
<id name="ProviderTitleDetailId" column="providerTitleDetailID" type="Guid">
<generator class="guid.comb" />
</id>
<one-to-one name="ProviderTitle" cascade="save-update" foreign-key="providerTitleID" />
<!--<many-to-one name="ProviderTitle" column="providerTitleID" cascade="save-update" not-null="true" />-->
<property name="Detail" column="detail" type="string" not-null="true" />
</class>
Code between sessionFactory.openSession() and session.close():Code:
using( ISession session = _sessionManager.OpenSession() )
{
providerTitle = new ProviderTitle();
ProviderTitleDetail ptd = new ProviderTitleDetail( titleDescription.ProviderDetail );
providerTitle.ProviderTitleDetail = ptd;
session.SaveOrUpdate( providerTitle );
session.Flush();
}
Name and version of the database you are using: SqlServer2005
The database tables are as such:
Code:
[dbo].[ProviderTitle](
[providerTitleID] [uniqueidentifier] NOT NULL
)
[dbo].[ProviderTitleDetail](
[providerTitleDetailID] [uniqueidentifier] NOT NULL,
[providerTitleID] [uniqueidentifier] NOT NULL,
[detail] [xml] NOT NULL,
)
The exception I'm getting is: "Cannot insert the value NULL into column 'providerTitleID', table 'DevTitle.dbo.ProviderTitleDetail'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."
So, I know the problem is in my mapping files. There is a 1 - 1 relationship between the ProviderTitle and ProviderTitleDetail tables. The ProviderTitleDetail is the sub-table of the ProviderTitle, and cannot exist without a ProviderTitle. A ProviderTitle may or may not have a ProviderTitleDetail.
Suggestions on mapping? Heck, even a pointer towards a section of documentation that cover this would be helpful. I'm not sure why NHibernate is not persisting the object correctly. If I debug the objects before I call Flush(), their IDs are set correctly.
Thanks.
[/code]