-->
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.  [ 8 posts ] 
Author Message
 Post subject: Many-to-one relation problem
PostPosted: Mon Jan 15, 2007 11:21 am 
Newbie

Joined: Mon Jan 15, 2007 10:09 am
Posts: 12
hi all!

I just want to know if by using a many-to-one relation, i could have the parent element. To explain my question, i have a Class Group and a Class Customer which mapping files are :

Groupe:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ArchivecoFramework" assembly="ArchivecoFramework">
  <class name="Groupe" table="V_GROUPE">
    <id name="NomGroupe">
      <column name="GROUPE"/>
      <generator class="assigned"/>
    </id>
    <set name="Clients" inverse="true" lazy="true">
      <key column="GROUPE"/>
      <one-to-many class="Client"/>
    </set>
  </class>
</hibernate-mapping>


Client :

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ArchivecoFramework" assembly="ArchivecoFramework">
  <class name="Client" table="FCLIENTREF">
   
    <id name="CodeClient">
      <column name="CODECLIENT" not-null="true"/>
      <generator class="assigned"/>
    </id>

    <property name="NomClient" column="NOMCLIENT" not-null="true"/>
    <property name="Actif" column="INACTIF" type="boolean"/>
    <property name="IpAutorisees" column="IPAUTORISEES" type="String"/>
    <property name="Ssl" column="SSL" type="boolean"/>

    <!--<property name="Groupe" column="GROUPE" not-null="true"/>-->

    <many-to-one name="GroupeParent" class="Groupe">
      <column name="GROUPE" not-null="true"/>
    </many-to-one>
   
    <bag name="Services" lazy="true">
      <key column="CODECLIENT"/>
      <one-to-many class="Service"/>
    </bag>
   
  </class>
</hibernate-mapping>


If i try to edit a HQL Query like

"IQuery query = session.CreateQuery("from Client");
comboBox1.DataSource = query.List();"

i just have an error message like "can't create a proxy instance".

Details :
"Creating a proxy instance failed
System.TypeLoadException: Access denied : 'ArchivecoFramework.Groupe'."


Can someone help me to resolve it ???

thx.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 2:54 am 
Beginner
Beginner

Joined: Mon Jan 08, 2007 11:59 pm
Posts: 31
Are you sure you have set all the properties in the class as virtual. This is needed for the lazy loading to work.

Job Samuel


Top
 Profile  
 
 Post subject: Re: Many-to-one relation problem
PostPosted: Tue Jan 16, 2007 3:53 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Samuel wrote:
Details :
"Creating a proxy instance failed
System.TypeLoadException: Access denied : 'ArchivecoFramework.Groupe'."


How is Your class declared? For lazy loading to work, the class must be public and not sealed.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 4:03 am 
Newbie

Joined: Mon Jan 15, 2007 10:09 am
Posts: 12
Thank you for your answer but i verify it thousand times and it' s not the problem. If you want some details to help me you can just ask me, i will reply quickly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 4:19 am 
Newbie

Joined: Mon Jan 15, 2007 10:09 am
Posts: 12
Thank you gert you were right. It was a problem with my class declaration. I forgot to put it public and let it with default settings (internal).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 4:47 am 
Newbie

Joined: Fri Sep 28, 2007 4:12 am
Posts: 15
This might be a bit of a thread resurrection but I'd like to add a little to the confusion.
I was getting the same Exception like Samuel on a ICriteria.List<some.type> call as soon as I had some many-to-one mapping in that particular mapping file in NHibernate 1.2.
All of the mapped classes were default internal and making them public fixed the Exception "Creating a proxy instance failed" with an inner exception message of "Access is denied: 'some.namespace.Reader'.":"" where this Reader was the class that was referenced to by the many-to-one relation.

Maybe someone can shed a little light on this one. For now I'm going on with the mapped objects declared as public because of .. well... "because of don't" :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 9:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
An "internal" class means nothing outside of the assembly has access to it. NHibernate, being obviously an assembly on its own, has no access to an internal class in a different assembly. Therefore, NH cannot create a proxy base on that class

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 4:34 am 
Newbie

Joined: Fri Sep 28, 2007 4:12 am
Posts: 15
Somehow it seems pretty obvious when I think about it a second time. I guess I should file this under "there is no magic" since accessing internal classes from outside the assembly clearly would require a lot of magic.
Thanks for clearing that one up!


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