I am stumped. In my application, I am trying to change data and save it to the database, but the changes never seem to save.
So, in trying to create a test case, I found that NHibernate is issuing a bunch of update statements for no reason. They are generated when I try to load an object using HQL.
I'm sure this is a mapping issue, because this is the only mapping where I'm using one table -> two classes.
Note: the Search.SearchByHQL is a function of mine, it simply builds an IQuery from the string and returns the IList or object.
Code:
MenuFolder mfTools = (MenuFolder)
Search.SearchByHQL("from MenuFolder as mf where mf.FolderName = 'Tools'", true);
Here is the log for that statement:
Code:
NHibernate: UPDATE fw_menu SET parent_menu_id = null WHERE parent_menu_id = :p0
:p0 = '5019'
NHibernate: UPDATE fw_menu SET parent_menu_id = null WHERE parent_menu_id = :p0
:p0 = '5016'
NHibernate: UPDATE fw_menu SET parent_menu_id = null WHERE parent_menu_id = :p0
:p0 = '5017'
NHibernate: UPDATE fw_menu SET parent_menu_id = null WHERE parent_menu_id = :p0
:p0 = '5020'
NHibernate: UPDATE fw_menu SET parent_menu_id = null WHERE parent_menu_id = :p0
:p0 = '5021'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5019'
:p1 = '5020'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5019'
:p1 = '5021'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5021'
:p1 = '5031'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5021'
:p1 = '5030'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5016'
:p1 = '5019'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5016'
:p1 = '5018'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5016'
:p1 = '5017'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5017'
:p1 = '5023'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5017'
:p1 = '5022'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5020'
:p1 = '5029'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5020'
:p1 = '5027'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5020'
:p1 = '5024'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5020'
:p1 = '5025'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5020'
:p1 = '5028'
NHibernate: UPDATE fw_menu SET parent_menu_id = :p0 WHERE menu_id = :p1
:p0 = '5020'
:p1 = '5026'
NHibernate: select menufolder0_.menu_id as menu_id, menufolder0_.menu_name as me
nu_name, menufolder0_.description as descript4_, menufolder0_.parent_menu_id as
parent_m5_ from fw_menu menufolder0_ where menufolder0_.menu_use_mode='1' and ((
menufolder0_.menu_name='Tools'))
And the mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ChemRex.Security.Menu, ChemRex.Security" table="fw_menu">
<id name="MenuID" column="menu_id" type="long">
<generator class="sequence">
<param name="sequence">fw_menu_seq</param>
</generator>
</id>
<discriminator column="menu_use_mode" type="String" length="1" />
<subclass name="ChemRex.Security.MenuFolder, ChemRex.Security" discriminator-value="1">
<property name="FolderName" column="menu_name" type="String" length="30" />
<property name="Description" column="description" type="String" length="100" />
<many-to-one name="ParentFolder" class="ChemRex.Security.MenuFolder, ChemRex.Security"
column="parent_menu_id" not-null="false" cascade="none" />
<set name="SubFoldersUntyped" table="fw_menu" inverse="false">
<key column="parent_menu_id" />
<one-to-many class="ChemRex.Security.MenuFolder, ChemRex.Security" />
</set>
<set name="SubItemsUntyped" table="fw_menu" inverse="false">
<key column="parent_menu_id" />
<one-to-many class="ChemRex.Security.MenuItem, ChemRex.Security" />
</set>
</subclass>
<subclass name="ChemRex.Security.MenuItem, ChemRex.Security" discriminator-value="2">
<property name="ItemName" column="menu_name" type="String" length="30" />
<property name="Description" column="description" type="String" length="100" />
<many-to-one name="Permission" class="ChemRex.Security.Permission, ChemRex.Security"
column="permission_id" not-null="false" cascade="none" />
<many-to-one name="ParentFolder" class="ChemRex.Security.MenuFolder, ChemRex.Security"
column="parent_menu_id" not-null="false" cascade="none" />
<property name="UserInterfacePageName" column="ui_page_name" type="String" length="100" />
<property name="UserInterfaceAssembly" column="ui_page_assembly" type="String" length="30" />
<property name="Mode" column="ui_page_mode" type="ChemRex.Data.MappingTypes.PageModeEnum, ChemRex.Data" />
</subclass>
</class>
</hibernate-mapping>