-->
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: [Urg] Hibernate cannot work with 2 open session
PostPosted: Sun Feb 22, 2009 3:36 am 
Newbie

Joined: Wed Sep 27, 2006 2:54 pm
Posts: 15
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.2.1.4000

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="IranWin.Core.DomainClasses" assembly="IranWin.Core" default-lazy="false" >
  <class name="User" table="Users" >
    <id column="Id" name="Id" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="Firstname" not-null="true" />
    <property name="Lastname" not-null="true" />
    <property name="Birthdate" not-null="true" />
    <property name="Email" not-null="true" />
    <property name="Phone" not-null="true" />
    <property name="MobilePhone" not-null="true" />
    <property name="Address" not-null="true" />
    <property name="Username" not-null="true" />
    <property name="Password" not-null="true" />
    <property name="RegisterDate" not-null="true" />
    <property name="Balance" not-null="true" />
    <property name="Score" not-null="true" />
    <property name="UserStatus" not-null="true" />
    <property name="UserLevel" not-null="true" />
    <property name="LastLoginDate" not-null="false" />

    <bag name="Transactions" cascade="all" lazy="true">
      <key column="UserId" />
      <one-to-many class="Transaction" />
    </bag>
   
    <bag name="Accounts" cascade="all" lazy="true" >
      <key column="UserId" />
      <one-to-many class="BankAccount" />
    </bag>

    <many-to-one name="Referer" column="RefererId" cascade="all" />
  </class>
</hibernate-mapping>


Name and version of the database you are using: MS SQL Server Express 2005


the problem is when i want to update the user i should load both Transactions and Accounts collection first , and then i can use SaveOrUpdate, otherwise it throws exception that Hibernate cannot work with 2 open session !

how can i solve this problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2009 5:24 pm 
Newbie

Joined: Thu Feb 26, 2009 4:36 pm
Posts: 6
Not sure I understand the problem.

Are you loading the children up in 1 session and then loading the parents in another and trying to save them all using the 2nd session?

If that's the case you either need to load them all up in 1 session or evict them from the first session and then add them to the 2nd session (the one with the parent) before trying to SaveOrUpdate.


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.