-->
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: joined-subclass with one-to-one problem
PostPosted: Wed Nov 16, 2005 1:39 pm 
Hello folks,

Got a class
Code:
class Customer : Company

And a property
Code:
class Customer { ... public CustomerInternetServiceDetail CustomerInternetServiceDetail { get; set; }... }

Trying to do polymorphic
Code:
(Customer)companyManager.FindCompanyByID( companyID );

it's instantiated w/o CustomerInternetServiceDetail. By the looks of the SQL, it's not joining or sub-selecting the CustomerInternetServiceDetail!

Full mapping follows...

Code:
   <class name="Company" table="Company">
      <id name="CompanyID" column="CompanyID" type="Int32" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property unique="true" column="CompanyName" type="String" name="CompanyName" not-null="true" length="250" />
      <property column="CompanyTypeID" name="CompanyTypeID" not-null="true" />
      <set name="Contacts" inverse="true" cascade="all" table="Contacts">
         <!--jcs-cache usage="read-write" /-->
         <key column="CompanyId" />
         <one-to-many class="Contact" />
      </set>
      <set name="Addresses" inverse="true" cascade="all" table="Address">
         <!--jcs-cache usage="read-write" /-->
         <key column="CompanyId" />
         <one-to-many class="Address" />
      </set>
   </class>

Code:
   <joined-subclass name="Customer" table="Customer" extends="Company" >

      <key column="CustomerID" />

      <!-- other stuff here -->
      <one-to-one name="InternetServiceDetail" class="CustomerInternetServiceDetail" cascade="all-delete-orphan" fetch="join" outer-join="true" />
   </joined-subclass>

Code:
   <class name="CustomerInternetServiceDetail" table="CustomerInternetServiceDetail">

      <id name="CustomerInternetServiceDetailID" column="CustomerID" type="Int32">
         <generator class="foreign" >
            <param name="property">Customer</param>
         </generator>
      </id>
      <one-to-one name="Customer" class="Customer" constrained="true" cascade="none" />
      <!-- other stuff here -->
      
   </class>


This works as expected though:
Code:
_session.Get( typeof(Customer), customerID)


If it's a bug in polymorphic fetch... it's scary. If there's something I missed in the mapping, I'd very much like to know what it is!

TIA,
E.


Top
  
 
 Post subject: Re: joined-subclass with one-to-one problem
PostPosted: Wed Nov 16, 2005 2:52 pm 
:oops: It's embarrasing, but I don't know what was it I did and it all works now :shock:

All the best to anyone having similiar issues!


Top
  
 
 Post subject: Re: joined-subclass with one-to-one problem
PostPosted: Wed Nov 16, 2005 3:13 pm 
E.T. wrote:
:oops: It's embarrasing, but I don't know what was it I did and it all works now :shock:

All the best to anyone having similiar issues!


Nope, sorry again, it doesn't. But I narrowed it down to something else:
Creating new Customer w/o the Detail record,
Followed by assignement of new Detail record and save the Customer,
Following read fetches no Detail record, even though it's in the DB at this point.

Probably something to do with how I save:


Code:
      public void SaveCompany(Company company, UserAccount modifiedBy)
      {
         if( company == null )
            throw new ArgumentNullException("company","Company required.");

         if( modifiedBy == null )
            throw new ArgumentNullException("modifiedBy","UserAccount required.");

         // open another session on the same connection (we have to close it if the transaction fails)
         using(ISession session = NHbServices.SessionFactory.Instance.NHibernateFactory
                 .OpenSession( _session.Connection, new NHbServices.AuditInterceptor( modifiedBy.UserAccountID )))
         {
            using(ITransaction tr = session.BeginTransaction())
            {
               try
               {
                  _session.Evict( company );
                  session.SaveOrUpdate( company );
                  tr.Commit();

                  session.Close();
               }
               catch( Exception e )
               {
                  tr.Rollback();
                  throw new ApplicationException("Unable to save the company.", e );
               }
            }
            _session.Refresh( company ); // reassociate with the session that stays open (in case there's anything lazy-loading later
         }
      }


Thanks for any insights,
E.


Top
  
 
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.