-->
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: Bug in equality of EntityKeys
PostPosted: Mon Apr 16, 2007 11:06 am 
Newbie

Joined: Mon Apr 16, 2007 10:24 am
Posts: 5
I guess I found a bug with regard to class hierarchies.

After requesting an object from the database that does exist, but isn't of the requested type, a new request for the right type will fail because its 'non-existance' is stored in the nonExists HashTable.

Hibernate version:
1.2 beta, current svn

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="test"
                   assembly="test"
                   auto-import="true"
                   default-access="field.pascalcase-m-underscore">

  <class name="BaseClass" discriminator-value="b">
    <id name="ID" column="ID">
      <generator class="native" />
    </id>
    <discriminator type="Char" column="Type"/>

    <subclass name="Sub1" discriminator-value="1">
    </subclass>

    <subclass name="Sub2" discriminator-value="2">
    </subclass>
  </class>
</hibernate-mapping>


Code:
Code:
session.Save(new Sub1());
session.Save(new Sub2());
session.Flush();
session.Clear();

Sub2 s2 = session.Get<Sub2>(1);
//Returns no results, but key is stored in nonExists hashtable

Sub1 s1 = session.Get<Sub1>(1);
//nonExists.Contains(key) is true => s1 = null
//DEBUG NHibernate.Impl.SessionImpl - entity does not exist

session.Clear();
//nonExists is empty again

s1 = session.Get<Sub1>(1);
//s1 is found


I did a quick workaround by disabling the check on nonExists in SessionImpl.cs. A better solution, I guess, would be to fix the GenerateHashCode() and/or Equals() methods of Engine/EntityKey.cs.


Top
 Profile  
 
 Post subject: Bug in caching non existing records
PostPosted: Thu Apr 19, 2007 10:55 am 
Newbie

Joined: Mon Apr 16, 2007 10:24 am
Posts: 5
I've looked into this somewhat further. Its not a bug in EntityKey (sorry :)).
It's only that non-existance can't be determined the way it is done right now.

The sql-query executed by session.Get<Sub2>(1) is
Code:
SELECT sub2x0_.ID as ID0_0_ FROM TestBase sub2x0_ WHERE sub2x0_.ID=@p0 and sub2x0_.Type='2'; @p0 = '1'

It selects the records where ID=1 and Type=Sub2 (discriminator=2). When the resultset is empty, it doesn't say anything about the existance of records of another subclass.
So the nonExists hashtable cannot be used with 'table per class hierarchy' and 'table per subclass'. Another option is to extend the key of nonExists to include the name of requested class.

I would be very thankfull if this issue can be solved in 1.2. In fact I'm already thankfull for the features NHibernate gives us. ;)


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.