-->
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.  [ 6 posts ] 
Author Message
 Post subject: "ambiguous match found" Exception with lazy=true i
PostPosted: Fri Jul 08, 2005 10:44 am 
Newbie

Joined: Fri Jul 08, 2005 10:23 am
Posts: 2
Hi friends of NHibernate!

I tried out NHibernate in a .Net 2.0 Project and I really like the flexibility of this tool.

It all works fine with one exception:

If I set "lazy=true" for a class, I'm getting an Exception "ambiguous match found" when I retrieve an object which references the lazy class.

I know that NHibernate does not support .Net 2.0 but if this bug will be fixed, it would be a great step in this direction.

Is there a chance to get this bug fixed in the next version?

Thanks in advance
- Ulrich Schumacher


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 11:23 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you give more details about your mapping and this exception? (post the content of the file "log.txt")

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 12:21 pm 
No, not the mapping, just the code that you use :) The problem may be caused by the fact that proxies override virtual properties and methods, so for a proxy class you have the original method and the overridden method. And if you don't tell the .NET framework which one you want, you may get the ambiguous match exception.


Top
  
 
 Post subject:
PostPosted: Sun Jul 17, 2005 7:19 am 
Newbie

Joined: Fri Jul 08, 2005 10:23 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 9:05 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Quote:
The problem may be caused by the fact that proxies override virtual properties and methods, so for a proxy class you have the original method and the overridden method. And if you don't tell the .NET framework which one you want, you may get the ambiguous match exception.


Writting:
Code:
<class name="DomainModel.Gender, DomainModel" table="GENDER" lazy="true">

Implies that all the members of DomainModel.Gender must be virtual.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: AmbiguousMatchException in the old forum
PostPosted: Tue Aug 16, 2005 5:10 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
Search the old forum for "AmbiguousMatchException" for a possible solution


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