-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: NHibernate 1.2.0b2, many-to-one and proxies
PostPosted: Sat Dec 30, 2006 12:15 pm 
Newbie

Joined: Sat Dec 30, 2006 11:48 am
Posts: 5
Hi...

I've encountered a serious problem recently - a few days ago - and I have absolutely no idea how to help myself..

It all started out with a mapping:
Code:
<class name="Folder" proxy="false">
  <id name="ID">
    <generator class="sequence">
      <param name="sequence">folder_id_sequence</param>
    </generator>
  </id>

  <property name="Name" />
  <property name="Type" />
  <many-to-one name="Owner" />
 
  <list name="Messages">
    <key column="folder_id" />
    <index />
    <one-to-many class="PrivateMessage" />
  </list>
</class>

This mapping compiles fine and serves me well - as long as I dont try to load anything from the Database. Each and every attempt to do such a thing gets interrupted by the ever-same exception: "Creating a proxy instance failed".

I've already tried to fix that by myself (playing with the mapping, visibility levels in the persisted class, etc), but nothing worked :(

Every property of the class is marked virtual and either a string, enum or another persisted class. And - as if it weren't weird enough that it doesn't work - it works after taking out the mapping for Owner. Marking it nonlazy works as well - but that's not what I intended.


Stacktrace:

Code:
   at NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Proxy\CastleProxyFactory.cs:line 71
   at NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy(Object id, ISessionImplementor session) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 1603
   at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\SessionImpl.cs:line 2596
   at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id, Boolean eager, Boolean isNullable) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\SessionImpl.cs:line 2500
   at NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Type\EntityType.cs:line 259
   at NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session, Object owner) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Type\EntityType.cs:line 279
   at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\SessionImpl.cs:line 2952
   at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Loader\Loader.cs:line 584
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Loader\Loader.cs:line 452
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Loader\Loader.cs:line 183
   at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Loader\Loader.cs:line 1757
   at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Loader\Loader.cs:line 1705
   at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Loader\Loader.cs:line 1699
   at NHibernate.Hql.Classic.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Hql\Classic\QueryTranslator.cs:line 1008
   at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\SessionImpl.cs:line 1810
   at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\SessionImpl.cs:line 1770
   at NHibernate.Impl.QueryImpl.List() in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Impl\QueryImpl.cs:line 57
   at SimpleTestProject.Program.Main(String[] args) in F:\Sources\STGQ\SimpleTestProject\Program.cs:line 39
   at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

_________________
Jolan'tru, Myeisha


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 12:50 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Try looking into InnerException property, and if you still don't understand the problem, post the whole InnerException chain here.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 1:24 pm 
Newbie

Joined: Sat Dec 30, 2006 11:48 am
Posts: 5
Ah, darn.. I knew I forgot something..

Okay, here it goes:

Code:
Exception has been thrown by the target of an invocation.

   at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
   at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(Type type, IInterceptor interceptor, Object[] argumentsForConstructor)
   at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type baseClass, Type[] interfaces, IInterceptor interceptor, Boolean checkAbstract, Object[] argumentsForConstructor)
   at NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session) in F:\NHibernate-1.2.0.Beta2-debug\src\NHibernate\Proxy\CastleProxyFactory.cs:line 58

And the inner exception of that one was a BadImageFormatException with HRESULT 0x8007000B.

_________________
Jolan'tru, Myeisha


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 4:25 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
In general, when we ask for the exception stack, we refer to the ENTIRE output of the exception.ToString()

Anyway, it looks like you have GenericMethod<T> on the entities, right?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 4:38 pm 
Newbie

Joined: Sat Dec 30, 2006 11:48 am
Posts: 5
Hmm... In the User-class, I indeed had two of them. After removing them, it works just fine :)

But, weird enough, other classes using the User lazily (at least I think they do) work yust fine.

Well, nevertheless thanks :) I guess I'll have to stick with casting then.

_________________
Jolan'tru, Myeisha


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 2:41 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
Ayende Rahien wrote:
...Anyway, it looks like you have GenericMethod<T> on the entities, right?


I have this problem too, and indeed I have a generic method on an entity.
I gather now, that this isn't allowed... I'm using 1.2

Code:
public virtual TFees GetFees<TFees>(ISet<TFees> fees) where TFees : IFees, new()
{ ...}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 6:23 am 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
Is this issue closed in 1.2GA?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 10:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
If you are getting a BadImageFormatException, generally it means you have a version mismatch between some DLL and your project. Are you using .net 1.1 and using the 2.0 version of NHibernate.dll?

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 11:02 am 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
karlchu wrote:
If you are getting a BadImageFormatException, generally it means you have a version mismatch between some DLL and your project. Are you using .net 1.1 and using the 2.0 version of NHibernate.dll?


No, I'm trying to migrate to NH 1.2GA. Now my application is using NH 1.0.4


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 11:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
What I meant was:
  1. What is the target .net version of your project? Are you using Visual Studio 2003?
  2. Which .net version of the NHibernate.dll are you using? Both NH 1.0 and 1.2 are distributed with two sets of DLLs: one is compiled to .net 1.1, the other is compiled to .net 2.0.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 11:29 am 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
karlchu wrote:
What I meant was:
  1. What is the target .net version of your project? Are you using Visual Studio 2003?
  2. Which .net version of the NHibernate.dll are you using? Both NH 1.0 and 1.2 are distributed with two sets of DLLs: one is compiled to .net 1.1, the other is compiled to .net 2.0.


Well,

1: The target version is .Net 2.0. I'm using VS 2005

2: Ahhhh, I'm using the set for 1.1!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 11:16 am 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
No, the problem is the same. I have build all with 2.0 target version but the exception still occurs.

If I remove the generics method I do not get the exception.

I have found some not answered posts about the same problem:

http://forum.hibernate.org/viewtopic.php?p=2367088

http://forum.hibernate.org/viewtopic.php?t=981884


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 12:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Try to replace all the DLLs that are related to NHibernate to the ones that are distributed with NH1.2. That includes the Castle, Iesi, and log4net DLL. Do not just replace the ones whose name starts with "NHibernate".

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 12:37 pm 
Beginner
Beginner

Joined: Tue Mar 14, 2006 9:15 am
Posts: 20
Location: Bitonto (BA) Italy
I'm using the following ones

Castle.DinamicProxy.dll 1.1.5.0
Iesi.Collections.dll 1.2.1.4000
log4net.dll 1.2.10.0
NHibernate.dll 1.2.1.4000
Nhibernate.Cashes.SysCache.dll 1.2.1.4000


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 2:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
The .NET 1.1 and 2.0 variants of the DLLs have the same version number. So the information you have given me does not help me help you. For the sake of completeness, just copy over all the NHibernate DLLs and make sure you are referencing the correct one in your projects and solution.

If you using any other libraries like Spring.NET, make sure you are using the ones with the correct target .NET version.

_________________
Karl Chu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.