Hibernate version:
NHibernate v2.2
Mapping documents:
User.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Save.Domain.User, Save" table="Users">
<id name="Id">
<generator class="native"/>
</id>
<!-- Access List -->
<bag name="LstAccess" inverse="true" cascade="all" lazy="false">
<key column="Id_User"/>
<one-to-many class="Save.Domain.Access, Save"/>
</bag>
<property name="State"/>
<property name="Username" unique="true" not-null="true"/>
<property name="Password" not-null="true"/>
<!--
<many-to-one class="Save.Domain.Profile, Save" column="Id" name="UserProfile"/>
-->
</class>
</hibernate-mapping>
Access.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Save.Domain.Access, Save">
<id name="Id">
<generator class="native"/>
</id>
<property name="AccessDateTime"/>
<many-to-one name="User" class="Save.Domain.User, Save" cascade="all" update="true">
<column name="Id_User" />
</many-to-one>
</class>
</hibernate-mapping>
Name and version of the database you are using:MSSQL 2005
HI there!
I have a one-to-many relation between User and Access. I use eager loading instead of lazy load, in order to get Access objects and associate them with their user. The problem is that I can't remove access objects from User's access list and persist the changes to the database. There is no exception coming through...
My test methods are :
Code:
[Test]
public void LogInApplication()
{
var user = new User("xpto1", "112233");
user = user.Login() as User;
Assert.IsNotNull(user);
Assert.Greater(user.LstAccess.Count, 0);
}
Code:
[Test]
public void DeleteAllAccesses()
{
var user = new User("xpto1", "112233");
user = user.Login() as User;
Assert.IsNotNull(user);
Assert.Greater(user.LstAccess.Count, 0);
var numElemens = user.LstAccess.Count;
//Delete accesses now ...
user.LstAccess.Clear();
user.UpdateExistingUser();
}
The first method is working fine . The former don't. The list is cleared, but when I do
user.UpdateExistingUser() ( wich is basically a session.Update() statement, nothing happens and my db Access table remains the same - untouched ...
Any suggestion ?
Best regards,
Ivan Frias
[/b]