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.  [ 2 posts ] 
Author Message
 Post subject: Eager Loading - Object not removed from db
PostPosted: Tue Nov 18, 2008 2:30 pm 
Newbie

Joined: Fri Nov 14, 2008 7:43 am
Posts: 7
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.xml

Code:
<?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]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 2:49 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
El método session.update() no hace lo que tú piensas que hace.
Por favor, ve mi artículo al respecto:

http://hibernar.org/articulos_en/persis ... ethods.php

_________________
Gonzalo Díaz


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

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.