Hibernate version:
1.2.0
First of all: Thank's a lot for the great product! I'm just starting using it but so far it works great.
But there's a little problem anyhow:
After retrieving objects I decorate them based on some business logic (see decorator pattern). The decorated objects behave exactely the same then the original objects but have some additional methods. When I try to store the objects I get the exception:
Code:
Unknown entity class: ....ClassName
Of course the decorators aren't mapped in the configuration and I don't want to do that as it would add a huge amount of dublicated mappings.
A possible solution would be a change in the GetEntityPersister(Type) in SessionFactoryImpl.cs:
Instead of:
Code:
public IEntityPersister GetEntityPersister(System.Type theClass)
{
IEntityPersister result = classPersisters[theClass] as IEntityPersister;
if (result == null)
{
throw new MappingException("Unknown entity class: " + theClass.FullName);
}
return result;
}
I would use:
Code:
public IEntityPersister GetEntityPersister(System.Type theClass)
{
IEntityPersister result = classPersisters[theClass] as IEntityPersister;
if (result == null)
{
if (theClass.BaseType == null || theClass.BaseType == typeof(object))
{
throw new MappingException("Unknown entity class: " + theClass.FullName);
}
else
{
return GetEntityPersister(theClass.BaseType);
}
}
return result;
}
If the mapping of a class isn't found if would try to find the mapping of the base class recursively.
Do you think this is a viewable solution?
Does it have any known side effects?
Should it be something in the core?
Should it be a behaviour that can be set in a config file?
Thanks in advance for your answers.
benedikt