Ok, I think I know what may be causing my particular issue. It may be the way I'm handling the session and transaction. The reason I suspect this is that I used Burrow for NHibernate for session management and re-factored my code to use it. Once I ran my unit test everything came out as expected which was no extra updates before the INSERT. Anyway I will do a bit more reading on Session management as it seems that I'm not to familiar with it as I thought.
On Saturday, June 28, 2014 12:20:40 PM UTC-7, Drexter Smith wrote: > > I've spent a couple of days researching this on Google, StackOverflow and > reading various blogs on this but to no avail. My question is if a > collection is updated within an entity then would this cause NHibernate to > update all properties in the entity of the modified collections? In this > case I've added a user to a role which goes into the junction table called > UserRoles and once I call session.SaveOrUpdate then 2 updates occur > (NHibernate updates user and role) then the INSERT occurs. Is this the > default behavior? I've tried to do the following to see if I can get > NHibernate to just issue the INSERT statement: > > 1. Ran a Ghostbuster test on these entities based on code by Jason > Dentler and Fabio Maulo but everything comes back ok and there are no > dirty > properties. > 2. I made properties nullable that are defined as null in the database. > 3. Set Inverse true on one of the entites. > 4. I removed cascade on both collections and now I only get on update > statement. > > Any help or insight is much appreciated. Thank you for your help > > Here are the mapping and class files. > > ============================= > <?xml version="1.0" encoding="utf-8"?> > > > > <hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace= > "Custom.NHibernateLib.Model" assembly="Custom.NHibernateLib" xmlns= > "urn:nhibernate-mapping-2.2"> > > <class name="Users"> > <id name="UserId" type="Int64"> > <generator class="hilo" /> > </id> > > <property name="ApplicationName" type="String" length="50" /> > <property name="Username" type="String" length="15" /> > <property name="Email" type="String" length="15" /> > <property name="Password" type="String" length="50" /> > <property name="PasswordSalt" type="String" length="128" /> > <property name="PasswordQuestion" type="String" length="15" /> > <property name="PasswordAnswer" type="String" length="50" /> > <property name="IsApproved" type="YesNo" /> > <property name="LastActivityDate" type="DateTime" /> > <property name="LastLoginDate" type="DateTime" /> > <property name="LastPasswordChangedDate" type="DateTime" /> > <property name="CreationDate" type="DateTime" /> > <property name="IsOnline" type="YesNo" /> > <property name="IsAnonymous" type="YesNo" /> > <property name="IsLockedOut" type="YesNo" /> > <property name="LastLockedOutDate" type="DateTime" /> > <property name="FailedPasswordAttemptCount" type="Int32" /> > <property name="FailedPasswordAttemptWindowStart" type="DateTime" /> > <property name="FailedPasswordAnswerAttemptCount" type="Int32" /> > <property name="FailedPasswordAnswerAttemptWindowStart" type="DateTime" /> > <property name="Comment" type="String" length="4001" /> > <bag name="RoleList" table="UserRoles" lazy="true" cascade="save-update, > persist" batch-size="10"> > <key column="UserId" not-null="true" /> > <many-to-many class="Roles" foreign-key="FK_Roles_UserRoles_RoleId"> > <column name="RoleId" not-null="true" /> > </many-to-many> > </bag> > <one-to-one name="Profiles" /> > </class> > </hibernate-mapping> > > > > > <?xml version="1.0" encoding="utf-8"?> > <hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace= > "Custom.NHibernateLib.Model" assembly="Custom.NHibernateLib" xmlns= > "urn:nhibernate-mapping-2.2"> > <class name="Roles"> > <id name="RoleId" type="Int64"> > <generator class="hilo" /> > </id> > > <property name="ApplicationName" type="String" length="50" /> > <property name="RoleName" type="String" length="50" /> > <bag name="UserList" table="UserRoles" lazy="true" inverse="true" > cascade="save-update, > persist" batch-size="10"> > <key column="RoleId" not-null="true"<span style="color: #000;" > class="styled-by-pre > ... -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.
