Sorry for the late reply, but I was very busy last days.
Here is my class Person:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
namespace DomainModel
{
public class Person
{
int id;
public int ID
{
get { return id; }
set { id = value; }
}
private string firstname;
public string Firstname
{
get { return firstname; }
set { firstname = value; }
}
private string lastname;
public string Lastname
{
get { return lastname; }
set { lastname = value; }
}
private DateTime birthday;
public DateTime Birthday
{
get { return birthday; }
set { birthday = value; }
}
private Gender gender;
public Gender Gender
{
get { return gender; }
set { gender = value; }
}
public static Person Get(int id)
{
ISession session = NHibernateManager.CreateSession();
Person person;
try
{
person = (Person)session.Load(typeof(Person), id);
session.Close();
}
catch (ObjectNotFoundException)
{
person = null;
session.Close();
}
catch (Exception ex)
{
session.Close();
// log the Exception
// ...
throw ex;
}
return person;
}
}
}
Here is my class Gender:
using System;
using System.Collections.Generic;
using System.Text;
namespace DomainModel
{
public class Gender
{
private int id;
public int ID
{
get { return id; }
set { id = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
}
Here are the mappings:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DomainModel.Person, DomainModel" table="PERSON">
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="identity">
</generator>
</id>
<property name="Firstname" column= "FIRSTNAME" />
<property name="Lastname" column= "LASTNAME" />
<property name="Birthday" column= "BIRTHDAY" />
<many-to-one name="Gender" column="GENDER_ID" class="DomainModel.Gender, DomainModel" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DomainModel.Gender, DomainModel" table="GENDER" lazy="true">
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="identity">
</generator>
</id>
<property name="Name" column= "NAME" />
</class>
</hibernate-mapping>
Now when I call
Person person = Person.Get(1);
I got the Exception.
Here is the log file:
2005-07-17 13:08:43,808 [NHibernate.Cfg.Environment] DEBUG no hibernate settings in app.config/web.config were found
2005-07-17 13:08:43,888 [NHibernate.Cfg.Configuration] INFO searching for mapped documents in assembly: DomainModel
2005-07-17 13:08:43,908 [NHibernate.Cfg.Configuration] INFO Found mapping documents in assembly: DomainModel.Person.hbm.xml
2005-07-17 13:08:44,199 [NHibernate.Dialect.Dialect] INFO Using dialect: NHibernate.Dialect.MsSql2000Dialect
2005-07-17 13:08:44,299 [NHibernate.Cfg.Binder] INFO Mapping class: DomainModel.Person -> PERSON
2005-07-17 13:08:44,399 [NHibernate.Cfg.Binder] DEBUG Mapped property: ID -> ID, type: Int32
2005-07-17 13:08:44,479 [NHibernate.Cfg.Binder] DEBUG Mapped property: Firstname -> FIRSTNAME, type: String
2005-07-17 13:08:44,479 [NHibernate.Cfg.Binder] DEBUG Mapped property: Lastname -> LASTNAME, type: String
2005-07-17 13:08:44,479 [NHibernate.Cfg.Binder] DEBUG Mapped property: Birthday -> BIRTHDAY, type: DateTime
2005-07-17 13:08:44,509 [NHibernate.Cfg.Binder] DEBUG Mapped property: Gender -> GENDER_ID, type: Gender
2005-07-17 13:08:44,509 [NHibernate.Cfg.Configuration] INFO Found mapping documents in assembly: DomainModel.Gender.hbm.xml
2005-07-17 13:08:44,509 [NHibernate.Dialect.Dialect] INFO Using dialect: NHibernate.Dialect.MsSql2000Dialect
2005-07-17 13:08:44,519 [NHibernate.Cfg.Binder] INFO Mapping class: DomainModel.Gender -> GENDER
2005-07-17 13:08:44,519 [NHibernate.Cfg.Binder] DEBUG Mapped property: ID -> ID, type: Int32
2005-07-17 13:08:44,519 [NHibernate.Cfg.Binder] DEBUG Mapped property: Name -> NAME, type: String
2005-07-17 13:08:44,589 [NHibernate.Cfg.Configuration] INFO processing one-to-many association mappings
2005-07-17 13:08:44,589 [NHibernate.Cfg.Configuration] INFO processing one-to-one association property references
2005-07-17 13:08:44,589 [NHibernate.Cfg.Configuration] INFO processing foreign key constraints
2005-07-17 13:08:44,599 [NHibernate.Cfg.Configuration] DEBUG resolving reference to class: Gender
2005-07-17 13:08:44,629 [NHibernate.Dialect.Dialect] INFO Using dialect: NHibernate.Dialect.MsSql2000Dialect
2005-07-17 13:08:44,639 [NHibernate.Cfg.SettingsFactory] INFO use outer join fetching: True
2005-07-17 13:08:44,639 [NHibernate.Connection.ConnectionProviderFactory] INFO Intitializing connection provider: NHibernate.Connection.DriverConnectionProvider
2005-07-17 13:08:44,649 [NHibernate.Connection.ConnectionProvider] INFO Configuring ConnectionProvider
2005-07-17 13:08:44,649 [NHibernate.Cfg.SettingsFactory] INFO Query language substitutions:
2005-07-17 13:08:44,649 [NHibernate.Cfg.SettingsFactory] INFO cache provider: NHibernate.Cache.HashtableCacheProvider
2005-07-17 13:08:44,659 [NHibernate.Cfg.Configuration] INFO instantiating and configuring caches
2005-07-17 13:08:44,679 [NHibernate.Impl.SessionFactoryImpl] INFO building session factory
2005-07-17 13:08:44,679 [NHibernate.Impl.SessionFactoryImpl] DEBUG instantiating session factory with properties: hibernate.connection.driver_class=NHibernate.Driver.OleDbDriver;hibernate.dialect=NHibernate.Dialect.MsSql2000Dialect;hibernate.connection.connection_string=***;hibernate.connection.provider=NHibernate.Connection.DriverConnectionProvider;
2005-07-17 13:08:45,070 [NHibernate.Impl.SessionFactoryObjectFactory] DEBUG initializing class SessionFactoryObjectFactory
2005-07-17 13:08:45,080 [NHibernate.Impl.SessionFactoryObjectFactory] DEBUG registered: c7c791dd8aa84029bcf47ef3152b559d(unnamed)
2005-07-17 13:08:45,080 [NHibernate.Impl.SessionFactoryObjectFactory] INFO no name configured
2005-07-17 13:08:45,080 [NHibernate.Impl.SessionFactoryImpl] DEBUG Instantiated session factory
2005-07-17 13:08:45,160 [NHibernate.Impl.SessionImpl] DEBUG opened session
2005-07-17 13:08:45,160 [NHibernate.Impl.SessionImpl] DEBUG loading [Person#1]
2005-07-17 13:08:45,170 [NHibernate.Impl.SessionImpl] DEBUG attempting to resolve [Person#1]
2005-07-17 13:08:45,180 [NHibernate.Impl.SessionImpl] DEBUG object not resolved in any cache [DomainModel.Person#1]
2005-07-17 13:08:45,180 [NHibernate.Persister.EntityPersister] DEBUG Materializing entity: DomainModel.Person#1
2005-07-17 13:08:45,210 [NHibernate.Impl.BatcherImpl] DEBUG about to open: 0 open IDbCommands, 0 open DataReaders
2005-07-17 13:08:45,230 [NHibernate.Impl.BatcherImpl] DEBUG Building an IDbCommand object for the SqlString: SELECT person0_.ID as ID0_, person0_.BIRTHDAY as BIRTHDAY0_, person0_.GENDER_ID as GENDER_ID0_, person0_.LASTNAME as LASTNAME0_, person0_.FIRSTNAME as FIRSTNAME0_ FROM PERSON person0_ WHERE person0_.ID = :person0_.ID
2005-07-17 13:08:45,230 [NHibernate.Type.NullableType] DEBUG binding '1' to parameter: 0
2005-07-17 13:08:45,230 [NHibernate.Loader.Loader] INFO SELECT person0_.ID as ID0_, person0_.BIRTHDAY as BIRTHDAY0_, person0_.GENDER_ID as GENDER_ID0_, person0_.LASTNAME as LASTNAME0_, person0_.FIRSTNAME as FIRSTNAME0_ FROM PERSON person0_ WHERE person0_.ID = ?
2005-07-17 13:08:45,240 [NHibernate.Impl.BatcherImpl] INFO Preparing SELECT person0_.ID as ID0_, person0_.BIRTHDAY as BIRTHDAY0_, person0_.GENDER_ID as GENDER_ID0_, person0_.LASTNAME as LASTNAME0_, person0_.FIRSTNAME as FIRSTNAME0_ FROM PERSON person0_ WHERE person0_.ID = ?
2005-07-17 13:08:45,240 [NHibernate.Connection.DriverConnectionProvider] DEBUG Obtaining IDbConnection from Driver
2005-07-17 13:08:45,561 [NHibernate.Loader.Loader] DEBUG processing result set
2005-07-17 13:08:45,571 [NHibernate.Loader.Loader] DEBUG result row: 1
2005-07-17 13:08:45,581 [NHibernate.Loader.Loader] DEBUG Initializing object from DataReader: 1
2005-07-17 13:08:45,591 [NHibernate.Loader.Loader] DEBUG Hydrating entity: DomainModel.Person#1
2005-07-17 13:08:45,601 [NHibernate.Type.NullableType] DEBUG returning '21.03.1953' as column: BIRTHDAY0_
2005-07-17 13:08:45,601 [NHibernate.Type.NullableType] DEBUG returning '2' as column: GENDER_ID0_
2005-07-17 13:08:45,611 [NHibernate.Type.NullableType] DEBUG returning 'Duck' as column: LASTNAME0_
2005-07-17 13:08:45,611 [NHibernate.Type.NullableType] DEBUG returning 'Donald' as column: FIRSTNAME0_
2005-07-17 13:08:45,621 [NHibernate.Loader.Loader] DEBUG done processing result set (1 rows)
2005-07-17 13:08:45,631 [NHibernate.Impl.BatcherImpl] DEBUG done closing: 0 open IDbCommands, 0 open DataReaders
2005-07-17 13:08:45,631 [NHibernate.Loader.Loader] DEBUG total objects hydrated: 1
2005-07-17 13:08:45,641 [NHibernate.Impl.SessionImpl] DEBUG resolving associations for: [DomainModel.Person#1]
2005-07-17 13:08:45,641 [NHibernate.Impl.SessionImpl] DEBUG loading [Gender#2]
2005-07-17 13:08:46,171 [NHibernate.Proxy.CastleProxyGenerator] ERROR Castle Dynamic Class Generator failed
Exception: System.Reflection.AmbiguousMatchException
Message: Ambiguous match found.
Source: mscorlib
at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetMethod(String name)
at Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.MethodTokenExpression.Emit(IEasyMember member, ILGenerator gen)
at Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.VirtualMethodInvocationExpression.Emit(IEasyMember member, ILGenerator gen)
at Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.AssignStatement.Emit(IEasyMember member, ILGenerator gen)
at Castle.DynamicProxy.Builder.CodeBuilder.AbstractCodeBuilder.Generate(IEasyMember member, ILGenerator il)
at Castle.DynamicProxy.Builder.CodeBuilder.EasyMethod.Generate()
at Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.EnsureBuildersAreInAValidState()
at Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.BuildType()
at Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateType()
at Castle.DynamicProxy.Builder.CodeGenerators.ClassProxyGenerator.GenerateCode(Type baseClass, Type[] interfaces)
at Castle.DynamicProxy.Builder.CodeGenerators.ClassProxyGenerator.GenerateCode(Type baseClass)
at NHibernate.Proxy.CastleProxyGenerator.GetProxy(Type persistentClass, Type concreteProxy, Type[] interfaces, PropertyInfo identifierPropertyInfo, Object id, ISessionImplementor session)
2005-07-17 13:08:46,232 [NHibernate.ADOException] ERROR could not load object
Exception: NHibernate.HibernateException
Message: Castle Dynamic Class Generator failed
Source: NHibernate
at NHibernate.Proxy.CastleProxyGenerator.GetProxy(Type persistentClass, Type concreteProxy, Type[] interfaces, PropertyInfo identifierPropertyInfo, Object id, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)
at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id)
at NHibernate.Type.ManyToOneType.ResolveIdentifier(Object id, ISessionImplementor session)
at NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session, Object owner)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)
Nested Exception
Exception: System.Reflection.AmbiguousMatchException
Message: Ambiguous match found.
Source: mscorlib
at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetMethod(String name)
at Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.MethodTokenExpression.Emit(IEasyMember member, ILGenerator gen)
at Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.VirtualMethodInvocationExpression.Emit(IEasyMember member, ILGenerator gen)
at Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.AssignStatement.Emit(IEasyMember member, ILGenerator gen)
at Castle.DynamicProxy.Builder.CodeBuilder.AbstractCodeBuilder.Generate(IEasyMember member, ILGenerator il)
at Castle.DynamicProxy.Builder.CodeBuilder.EasyMethod.Generate()
at Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.EnsureBuildersAreInAValidState()
at Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.BuildType()
at Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateType()
at Castle.DynamicProxy.Builder.CodeGenerators.ClassProxyGenerator.GenerateCode(Type baseClass, Type[] interfaces)
at Castle.DynamicProxy.Builder.CodeGenerators.ClassProxyGenerator.GenerateCode(Type baseClass)
at NHibernate.Proxy.CastleProxyGenerator.GetProxy(Type persistentClass, Type concreteProxy, Type[] interfaces, PropertyInfo identifierPropertyInfo, Object id, ISessionImplementor session)
2005-07-17 13:08:46,282 [NHibernate.Impl.SessionImpl] DEBUG closing session
2005-07-17 13:08:46,282 [NHibernate.Impl.SessionImpl] DEBUG disconnecting session
2005-07-17 13:08:46,282 [NHibernate.Connection.ConnectionProvider] DEBUG Closing connection
2005-07-17 13:08:46,332 [NHibernate.Impl.SessionImpl] DEBUG transaction completion
Thanks in advance
- Ulrich Schumacher
|