-->
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.  [ 1 post ] 
Author Message
 Post subject: problem with idbag updating version column
PostPosted: Thu May 12, 2011 11:56 pm 
Newbie

Joined: Thu May 12, 2011 3:26 pm
Posts: 1
I have a problem using the idbag. In my database I have a User table and a Role table and between them a many-to-many join relationship table UserRole. My User class has a list of roles, and my Role class has a list of users. From my configuration:

USER:

<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name="Business.Domain.User,Business" table="User" lazy="true" optimistic-lock="version" dynamic-update="true" dynamic-insert="true" >
<cache usage="read-write" />
<id name="Guid" column="[UserGUID]" type="Guid">
<generator class="assigned" />
</id>


<version name="RowVersion" />


<property column="[AccountLockoutFlag]" type="Boolean" name="AccountLockoutFlag" not-null="true" />
<property column="[ActiveFlag]" type="Boolean" name="ActiveFlag" not-null="true" />
<property column="[CanSeeMeFlag]" type="Boolean" name="CanSeeMeFlag" not-null="true" />
<property column="[DomainIdentity]" type="String" name="DomainIdentity" length="256" />
<property column="[HasCustomizedHomePageFlag]" type="Boolean" name="HasCustomizedHomePageFlag" />
<property column="[Password]" type="String" name="EncryptedPassword" not-null="true" length="256" />
<property column="[PasswordExpirationDate]" type="timestamp" name="PasswordExpirationDate" />
<property column="[UserName]" type="String" name="Name" not-null="true" length="256" />
<property column="[UserPreferences]" type="String" name="Preferences" length="2147483647" />

<idbag name="ListOfRole" lazy="true" inverse="true" collection-type="Business.Domain.RolePersistentIdListType,Business" table="UserRole" cascade="save-update">
<collection-id column="UserRoleGUID" type="Guid">
<generator class="guid" />
</collection-id>
<key column="UserGUID"/>
<many-to-many class="Business.Domain.Role,Business" column="RoleGUID" />
</idbag>
</class>
</hibernate-mapping>

ROLE:

<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name="Business.Domain.Role,Business" table="Role" lazy="true" optimistic-lock="version" dynamic-update="true" dynamic-insert="true" >
<cache usage="read-write" />
<id name="Guid" column="[RoleGUID]" type="Guid">
<generator class="assigned" />
</id>


<version name="RowVersion" />


<property column="[Comments]" type="String" name="Comments" length="2147483647" />
<property column="[RoleName]" type="String" name="Name" not-null="true" length="50" />

<idbag name="ListOfUser" lazy="true" inverse="false" collection-type="Business.Domain.UserPersistentIdListType,Business" table="UserRole" cascade="save-update">
<collection-id column="UserRoleGUID" type="Guid">
<generator class="guid" />
</collection-id>
<key column="RoleGUID"/>
<many-to-many class="Business.Domain.User,Business" column="UserGUID" />
</idbag>
</class>
</hibernate-mapping>

When I add a role to a user, and call ISession.Save, the version column RowVersion is set to the same value it is in the database. However, after a call to ISession.Flush, the version column has been changed for the Role, and looking in my database I see that an update statement has been executed against my Role table where the only thing that changed is the version column.

Is this the desired behavior? Can someone explain to me if there is a way I can avoid having this happen? The Role object is not changing at all, and it should not be updating.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.