No persister for: Castle.Proxies. <EntityName> Proxies and lazy = "true" in NHibernate?

I am trying to use lazy loading for a property of one of my objects

Property mapping looks something like this:

<property name="Foobar" type="AnsiString" column="FOOBAR" lazy="true"/> 

However, when I try to save an instance of these objects (using Linq), it throws a DatabaseQueryException with the following internal exception:

NHibernate.MappingException : Not required for: Castle.Proxies.FooEntityProxy "

And when I remove the lazy = "true" element, the exception will no longer be thrown. What is the problem with using lazy = "true" and how to fix it?

+7
source share
3 answers

I know this is a late answer, but I had the same problem before. I used a special interceptor to create a proxy, and so I found that the problem was that I did not override the GetEntityName method. Analyzing the proxy in the GetEntityName method and returning the correct class name did the trick.

In my case, I had a simple extension method for unproxy my objects, called "UnProxy", so my whole implementation of this method looked like this:

 public override string GetEntityName(object entity) { if (entity == null) return base.GetEntityName(entity); return entity.UnProxy().GetType().FullName; } 
+4
source

Are you sure you are using NHibernate 3? I think that only this version supports scalar properties of lazy loading!

Update

Not sure if it can help you, but try looking here:

NHibernate Low-Boot Download Property - What Does Build-Time Bytecode Hardware Mean?

or here:

Unsaturation of NHibernate?

+3
source

If you mark a property as lazy, it should be a virtual automatic property (without a body, such as public virtual MyType Baz { get; set; } ). If you try to access the base value of a field, instead of going through this property, you will bypass the lazy loading of the property and be able to get unexpected results.

+2
source

All Articles