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: My fault but nasty anyway
PostPosted: Sun Apr 13, 2008 12:00 pm 
Regular
Regular

Joined: Mon Mar 20, 2006 10:49 pm
Posts: 59
b]Hibernate version:[/b]
2.0 Alpha 1

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Monitor.Udr.Application.CustomScreens.BLL" namespace="Monitor.Udr.Application.CustomScreens.DomainModel">

<class name="Activity" table="ACACTIVITY">
<cache usage="read-only"/>

<id type="string" name="Id" column="ACTIVITY" length="15">
<generator class="assigned"/>
</id>

<set name="MilestoneSummarys">
<key column="ACTIVITY"/>

<one-to-many class="MilestoneSummary"/>
</set>
</class>

</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Monitor.Udr.Application.CustomScreens.BLL" namespace="Monitor.Udr.Application.CustomScreens.DomainModel">

<class name="MilestoneSummary" schema="dbo" table="NHACMILESTN">
<cache usage="read-only"/>

<id access="field" name="m_milestoneKey" column="MILESTONE_KEY">
<generator class="assigned"/>
</id>

<discriminator column="MILESTONE_CAT" type="String"/>

<property name="m_activityId" access="field" column="ACTIVITY"/>
<property name="m_milestoneCat" access="field" column="MILESTONE_CAT"/>

<many-to-one name="Activity" column="ACTIVITY" />

<subclass name="RevenueMilestoneSummary" discriminator-value="R"/>

<subclass name="BillingMilestoneSummary" discriminator-value="B"/>

</class>

Code between sessionFactory.openSession() and session.close():
Activity a = SessionManager.CurrentSession.Get<Activity>("2ND-BAC-CONT");

foreach (MilestoneSummary ms in a.MilestoneSummarys)
{
decimal amt = ms.Balance;
}

Name and version of the database you are using:
SQL Server 2000

I'm posting this so someone else doesn't have to spend a day trying to figure out what's wrong.

Briefly, the Id column, ACTIVITY, of the Activity class is char(15). If I get an Activity using

Activity a = SessionManager.CurrentSession.Get<Activity>("2ND-BAC-CONT");

everything appears to work, but Activity.MilestoneSummarys is empty. If I get the same Activity using

Activity a = SessionManager.CurrentSession.Get<Activity>("2ND-BAC-CONT ");

(the Id is padded out to 15 characters), the MilestoneSummarys collection is populated correctly. This behavior is at least surprising. Presumably, it's due to some confusion about the precise value of the object identity, and NHibernate is being stricter than the database.

IMO, it would be better to fail the initial Get() with the truncated key, than to have the Get() succeed but have various object relationships silently broken.

_________________
Mike Abraham


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 14, 2008 11:11 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Yes, this a a very nasty, subtle problem. See this post:
http://forum.hibernate.org/viewtopic.php?t=975743


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.