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.  [ 2 posts ] 
Author Message
 Post subject: Simple relational mapping problem
PostPosted: Wed Feb 04, 2009 6:45 pm 
Newbie

Joined: Wed Feb 04, 2009 6:13 pm
Posts: 1
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]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 4:10 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I think you need to put constrained="true" to the other end of the association.

_________________
--Wolfgang


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