-->
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: Adding one-to-many and getting unmapped class
PostPosted: Tue Dec 22, 2009 1:53 pm 
Beginner
Beginner

Joined: Thu Oct 08, 2009 11:44 am
Posts: 21
Location: Chicago
Having trouble using one-to-many association. I think someone should put up a check list of what you need for each type of association. The examples always show one way to do things and it is always using features I don't care to.

What I have are two tables. An associate table and a user_permissions table.

I am using VB and VS2008 and nhibernate 2.1.0.4000

I have the two tables set up with the approriate .hbm.xml files set as embedded resources. With the association removed I can run the program and do a query and print out the values of both tables, ergo the tables are getting mapped and used fine.

But when I add in an association and run the same program, The program gets an exception when it tries to access the DB_User_Permissions in a query that works when the association is not there, and I get the:

'Association references unmapped class: DB_User_Permissions' message saying that added association is not connecting to the existing class. The association I added is

Code:
  <set name="User_Permissions" lazy="false">
    <key  column ="User_ID"/>
    <one-to-many class="DB_User_Permissions"/>
  </set>

There is a forgien key defined in User_Permssions assoicating the User_ID with User_Id in Association

The .hbm. files are

Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="<assembly>.DBWrappers.DB_Associate, <assembly>" lazy="false" table="Associate">

    <id name="User_ID" type="integer" column="User_ID">
       <generator class="native" />
    </id>
    <property name="User_Name" type="string" column="User_Name"/>
    <property name="Last_Name" type="string" column="Last_Name"/>
    <property name="First_Name" type="string" column="First_Name"/>
    <property name="Phone_Number" type="string" column="Phone_Number"/>
    <property name="Group_ID" type="integer" column="Group_ID"/>
    <property name="Supervisor_ID" type="integer" column="Supervisor_ID"/>
    <property name="Email" type="string" column="Email"/>
    <property name="External_Only" type="string" column="External_Only"/>
    <property name="Has_External" type="string" column="Has_External"/>
  <set name="User_Permissions" lazy="true">
    <key  column ="User_ID"/>
    <one-to-many class="DB_User_Permissions"/>
  </set>
</class>
</hibernate-mapping>



and

Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="<assembly.DBWrappers.DB_User_Permissions, <assembly" lazy="false" table="User_Permissions">

    <id name="User_Id" type="integer" column="User_Id">
       <generator class="native" />
    </id>
    <property name="Permission_Id" type="integer" column="Permission_Id"/>
    <property name="Crt_Date" type="string" column="Crt_Date"/>
    <property name="Who_Crt" type="string" column="Who_Crt"/>
    <property name="Permission_Disabled" type="String" column="Permission_Disabled"/>
    <many-to-one name="User" column="User_Id"/>

</class>
</hibernate-mapping>


And some code in the DB_Associates table (I add DB_ to the table name for the class)
that was uncommented out along with including the <set in the .hbm. to generated this error

Code:
        Private _User_Permissions As IList

...

        '------------------------------------------------------------------------------------------------
        '---------Get/Set for virtual list of permissions: List of ser_Permissions
        '------------------------------------------------------------------------------------------------

        Public Property User_Permissions() As IList

            Get
                Return _User_Permissions
            End Get
            Set(ByVal Value As IList)
                _User_Permissions = Value
            End Set
        End Property



Anyone have a clue what is wrong here?


Thanks

---John Putnam


Top
 Profile  
 
 Post subject: Re: Adding one-to-many and getting unmapped class
PostPosted: Tue Dec 22, 2009 5:17 pm 
Beginner
Beginner

Joined: Thu Oct 08, 2009 11:44 am
Posts: 21
Location: Chicago
I worked around the problem. the
Code:
  <set name="User_Permissions" lazy="false">
    <key  column ="User_ID"/>
    <one-to-many class="<assemblyname>.DBWrappers.DB_User_Permissions, <assemblyname>"/>
  </set>



<actual assembly name replaced above>

needed the assembly name.namespace.class, assembly in the class parameter. that and importing Iesi.Collections in a few places. But I got the mapping to finally work.

---John Putnam


Top
 Profile  
 
 Post subject: Re: Adding one-to-many and getting unmapped class
PostPosted: Wed Dec 23, 2009 2:51 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can add the assembly and the namespace to the surrounding class tag:

<class name="DB_Associate, <assembly>" lazy="false" table="Associate" assembly="<assembly>" namespace="="<assembly>.DBWrappers">

Than you don't need to use fully qualified references.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Adding one-to-many and getting unmapped class
PostPosted: Wed Dec 23, 2009 5:56 pm 
Beginner
Beginner

Joined: Thu Oct 08, 2009 11:44 am
Posts: 21
Location: Chicago
Thanks,

Thats good information


Top
 Profile  
 
 Post subject: Re: Adding one-to-many and getting unmapped class
PostPosted: Mon Dec 28, 2009 4:30 pm 
Beginner
Beginner

Joined: Thu Oct 08, 2009 11:44 am
Posts: 21
Location: Chicago
Wolfgang,

Actually NHibernate does not have the assembly or namespace defined in the documenation and it throws an exception when you have it in the xml. That may be a hibernate feature that has not been tranfered over. It would be a nice one though.

Thanks,

---John Putnam


Top
 Profile  
 
 Post subject: Re: Adding one-to-many and getting unmapped class
PostPosted: Tue Dec 29, 2009 5:09 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Sorry, they are not defined on the class, but the outer hibernate-mapping element:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="sx.business" namespace="sx.business.partner">

_________________
--Wolfgang


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.