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