-->
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: Possible bug getting <any> class?
PostPosted: Thu Nov 03, 2005 10:57 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
I've got an NHibernate entity class (LogItem) with one of it's properties property mapped as any representing the parent to which the LogItem belongs. The any mapping uses the meta-type tag to specify the strategy for the names persisted to the classes represented.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Core.Entities" assembly="Core" default-access="field.camelcase">
   
   <class name="LogItem" table="Logs" lazy="true">
      
      <id name="Id" column="LogID" unsaved-value="0" >
         <generator class="native" />
      </id>
      
      <property name="Message" column="Message" length="4000"  />
      <property name="Severity" column="Severity"  />

      <any name="ParentEntity" id-type="Int32" meta-type="string" >
         <meta-value value="Core.Entities.Customer" class="Customer"/>
         <meta-value value="Core.Entities.Trigger" class="Trigger"/>
         <meta-value value="Core.Entities.User" class="User"/>
         
         <column name="ParentEntityType"/>
         <column name="ParentEntityID"/>
         
      </any>
         
   </class>
   
</hibernate-mapping>


When executing a query that instantiates a new POCO entity (not an NHibernate entity) using the following query...

Code:
SELECT new DTItem(log.Id, log.ParentEntity.class, log.ParentEntity.id) FROM LogItem log


...where the DTItem class is as follows...

Code:
public class DTItem
{

    public int ItemId;
    public object ParentEntityType;
    public int ParentEntityId;

    public DTItem()
    {}

    public DTItem(int id, object parentEntityType, int parentEntityId)
    {

        this.ItemId = id;
        this.ParentEntityType = parentEntityType;
        this.ParentEntityId = parentEntityId;
    }

}


...the parentEntityType in the constructor is null.

The parentEntityId has a value and I've looked in the log4net debug output and seen that the string specified in the mapping is being returned in the resultset, so I have to assume that there's a problem in the NHibernate code that generates the new object returned when the '.class' special property is used in a query (I'm just expecting object, but I would assume that it's going to return a System.Type, right?).

Can anyone else confirm that this is a bug?

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 11:39 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Never mind. DUH!

After spending some more time stepping through the code I discovered that it was due to a change that had been made to a derived class used in the any mapping that was causing the problem. The string persisted in the database referred to the base class name but the base class was no longer provided in the <meta-type> list, only the derived classes.

What I discovered in the interim, however, is that if the return type it detects does not match any of the meta-types defined then the scalar returned from the ".class" element then NHibernate will simply be null rather than throwing an exception.

Wouldn't it be better to throw an exception?

Cheers,

Symon.


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.