-->
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.  [ 5 posts ] 
Author Message
 Post subject: Reflection optimizer breaks on collection mapping?
PostPosted: Thu Mar 30, 2006 10:58 am 
Newbie

Joined: Wed Mar 22, 2006 9:39 am
Posts: 2
Hello,

Can anybody tell me, please, whether it is possible to declare access="nosetter.*" in a field mapping of collection type (e.g. IList) so that reflection optimizer could apply to the mapped class? If yes, what is wrong in the example below where reflection optimizer becomes disabled?
I tried to map classes like
Hibernate version:
1.0.2.0
Mapping documents:
Code:
<class name="Foo">
    <id name="Id" type="long" unsaved-value="0" access="nosetter.camelcase-underscore">
      <generator class="identity"/>
    </id>
    <set name="Boos" inverse="true" cascade="all" lazy="true" access="nosetter.camelcase-underscore">
      <key column="FooId"/>
      <one-to-many class="Boo"/>
    </set>
</class>

<class name="Boo">
    <id name="Id" type="long" unsaved-value="0">
      <generator class="identity"/>
    </id>
</class>

However this results in an NRE exception while building session factory, which effectively disables reflection optimizer for Foo.
Debug level Hibernate log excerpt:
NHibernate.Persister.GetSetHelperFactory.CreateGetSetHelper [4952] INFO - Disabling reflection
optimizer for class Sample.Foo
NHibernate.Persister.GetSetHelperFactory.CreateGetSetHelper [4952] DEBUG - CodeDOM compilation failed
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: NHibernate at NHibernate.Persister.GetSetHelperFactory.GenerateCode() in C:\net\nHibernate-1.0.2.0\src\NHibernate\Persister\GetSetHelperFactory.cs:line 241

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 11:33 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
The optimizer only works with the default "property" access method. With "nosetter.*", there's no way for the optimizer to assign values to your object. You can keep your desired mapping, which is good I think, but NHibernate will have to use reflection to set the values of your class members.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 12:06 pm 
Newbie

Joined: Wed Mar 22, 2006 9:39 am
Posts: 2
Thanks a lot!
Is it possible then to expose the collection as read-only like this:
Code:
    public class Foo
    {
        private int _id;
        private ISet _boos = new HybridSet();

        public int Id
        {
            get { return _id; }
        }

        public ISet Boos
        {
            get { return _boos; }
         }
    }


I thought that declaring access="nosetter.." means that writes to Boos are made via reflected field Foo._boos, while reads are made via Foo.Boos property. Access to other members is optimized though. However it seems it disables optimizer for the whole class (as side-effect I guess). Is it true?

Many Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 12:18 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 7:25 pm
Posts: 43
Location: Somewhere, USA
Have you tried this version of NHibernate? It has a different reflection optimizer implementation that may work. I haven't tested in that scenario, though.

http://forum.hibernate.org/viewtopic.php?t=956966


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 12:56 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Dmitry Yegorov wrote:
I thought that declaring access="nosetter.." means that writes to Boos are made via reflected field Foo._boos, while reads are made via Foo.Boos property. Access to other members is optimized though. However it seems it disables optimizer for the whole class (as side-effect I guess). Is it true?


Yes, as I understand it the reflection optimizer is all or nothing for a class. You might try the other optimizer implementation mentioned by smudges - please post your experience with it.


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