component and properties lazy loading not working (nhibernate 3)

508 views
Skip to first unread message

Ah

unread,
Dec 1, 2011, 5:36:46 PM12/1/11
to nhusers
Hi,

I try to use lazy=true on a component (which encapsulate a blob) to
avoid unecessary data transfer between the database and the
application.

Mapping :

<class name="Candidate" table="Candidate">
<!-- id, properties, etc... -->
<component name="Resume" class="Common.Model.Enclosure"
lazy="true">
<property name="Document" column="RESUME" type="BinaryBlob"/>
<property name="Suffix" column="RESUME_FILE_TYPE" />
</component>
</class>

The query :
IList<Candidate> candidates = session.CreateQuery("select c from
Candidate").List<Candidate>();
or
IList<Candidate> candidates = session.CreateQuery("from
Candidate").List<Candidate>();

The SQL generated include RESUME and RESUME_FILE_TYPE columns.
I also tried to add lazy=true on each property (Document and Suffix) :
same problem.

And it does not work either on basic property.

I use Nhibernate 3.2, sessionManagement (GetCurrentSession()) with
spring but I doubt it has anything to do with Spring since it's just
about how hql is transformed in SQL.

Did I miss something in the hibernate sessionFactory configuration ?

I use the following configuration :

dialect = NHibernate.Dialect.MsSql2008Dialect
connection.provider" ="NHibernate.Connection.DriverConnectionProvider
connection.driver_class = NHibernate.Driver.SqlClientDriver
cache.provider_class = NHibernate.Caches.SysCache2.SysCacheProvider,
Hibernate.Caches.SysCache2
cache.use_query_cache = false
hibernate.cache.use_second_level_cache = true

Thanks,


Ah

unread,
Dec 6, 2011, 6:00:19 PM12/6/11
to nhusers
Hi,

No idea ? Is there any working sample somewhere ?
If it does not work there is no way to store blob in the DB without
additional table (!)

Thanks,

belva...@googlemail.com

unread,
Dec 7, 2011, 4:21:57 AM12/7/11
to nhu...@googlegroups.com
I don't know if lazy loading is possible with components, but i think it should work if
the Enclosure is an entity with one to one relation to Candidate.

Am schrieb Ah <alariche...@gmail.com>:

> Hi,
>
>
>
> No idea ? Is there any working sample somewhere ?
>
> If it does not work there is no way to store blob in the DB without
>
> additional table (!)
>
>
>
> Thanks,
>
>
>
>
>
>
>
>
>
>
>
> On Dec 1, 11:36 pm, Ah alarichermant1...@gmail.com> wrote:
>
> > Hi,
>
> >
>
> > I try to use lazy=true on a component (which encapsulate a blob) to
>
> > avoid unecessary data transfer between the database and the
>
> > application.
>
> >
>
> > Mapping :
>
> >
>
> >
>
> >
>
> >    
> > lazy="true">
>
> >      
>
> >      
>
> >    
>
> >
>
> >
>
> > The query :
>
> > IList candidates = session.CreateQuery("select c from
>
> > Candidate").List();
>
> > or
>
> > IList candidates = session.CreateQuery("from
>
> > Candidate").List();

>
> >
>
> > The SQL generated include RESUME and RESUME_FILE_TYPE columns.
>
> > I also tried to add lazy=true on each property (Document and Suffix) :
>
> > same problem.
>
> >
>
> > And it does not work either on basic property.
>
> >
>
> > I use Nhibernate 3.2, sessionManagement (GetCurrentSession()) with
>
> > spring but I doubt it has anything to do with Spring since it's just
>
> > about how hql is transformed in SQL.
>
> >
>
> > Did I miss something in the hibernate sessionFactory configuration ?
>
> >
>
> > I use the following configuration :
>
> >
>
> > dialect = NHibernate.Dialect.MsSql2008Dialect
>
> > connection.provider" ="NHibernate.Connection.DriverConnectionProvider
>
> > connection.driver_class = NHibernate.Driver.SqlClientDriver
>
> > cache.provider_class = NHibernate.Caches.SysCache2.SysCacheProvider,
>
> > Hibernate.Caches.SysCache2
>
> > cache.use_query_cache = false
>
> > hibernate.cache.use_second_level_cache = true
>
> >
>
> > Thanks,
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "nhusers" group.
>
> To post to this group, send email to nhu...@googlegroups.com.
>
> To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
>
> For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
>
>
>
>

Jason Meckley

unread,
Dec 7, 2011, 8:37:55 AM12/7/11
to nhu...@googlegroups.com
I thought lazy properties only works with the Castle Proxy Factory Factory. IIRC NH 3.x uses LinFu as the proxy factory factory. I would assume this is still a configurable option where you could replace LinFu with Castle.

If this isn't possible the next option is to refactor the database and convert the component to an entity with a 1:1 relationship.
Reply all
Reply to author
Forward
0 new messages