-->
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: FlushMode.NEVER and session.update problem
PostPosted: Thu Feb 24, 2005 6:27 pm 
Newbie

Joined: Thu Feb 24, 2005 5:21 pm
Posts: 5
Hibernate version: 2.1

Mapping documents:

Parent class:
<class name="ncr.dpc.domain.Promotion" table="PROMOTIONS">
<id name="id" column="promotionId" type="integer" unsaved-value="null">
<generator class="native"/>
</id>
<property name="code" type="integer"/>
<property name="customerEmployeeDiac" type="boolean"/>
<property name="customerNotEmployeeDiac" type="boolean"/>
<property name="customerRecordDiac" type="boolean"/>
<property name="description" type="string"/>
<property name="directed" type="boolean"/>
<property name="instantWin" type="boolean"/>
<property name="instantWinEvaluationMode" type="integer"/>
<property name="instantWinPrizeOddsOfWinning" type="integer"/>
<property name="instantWinPrizeQuantity" type="integer"/>
<property name="instantWinOddsCalculation" type="integer"/>
<property name="endDate" type="date"/>
<property name="endTime" type="string"/>
<property name="offlineDiac" type="integer"/>
<property name="priority" type="integer"/>
<property name="rewardLimitation" type="integer"/>
<property name="rewardLimitationTimes" type="integer"/>
<property name="rewardLimitationTransaction" type="integer"/>
<property name="startDate" type="date"/>
<property name="startTime" type="string"/>
<property name="state" type="integer"/>
<many-to-one name="promotionVariable" column="promotionVariableId" class="ncr.dpc.domain.PromotionVariable"/>
<many-to-one name="originalPromotion" class="ncr.dpc.domain.Promotion" column="originalPromotionId" unique="true"/>
<many-to-one name="category" class="ncr.dpc.domain.PromotionCategory" column="promotionCategoryId"/>
<list name="conditions" cascade="all-delete-orphan" lazy="true" access="field">
<key column="promotionId"/>
<index column="position"/>
<one-to-many class="ncr.dpc.domain.condition.Condition"/>
</list>
</class>


Code between sessionFactory.openSession() and session.close():

This is the method in the persistence layer to initialize a lazy collection
Code:
   public List retrieveConditions(Promotion promotion) throws NCRHomeException {
      Session session =  getSession();
      session.setFlushMode(FlushMode.NEVER);
      Transaction tr;
      try {
         tr = session.beginTransaction();
         session.update(promotion);
         if (!Hibernate.isInitialized(promotion.conditions)) {
            Hibernate.initialize(promotion.conditions);
         }
         tr.rollback();
         return promotion.conditions;
      } catch (HibernateException e) {
         //@TODO Log
         throw new HomeException(e);
      } finally {
         this.closeSession(session);
      }
   }


Name and version of the database you are using:
MySql 4.1.8


The case is that a need to work with the objects over several transactions, only saving it when the user presses the save button. The problem arises when a add a new object to the lazy collection. For some reason, the session.updates() does update the lazy collection, inserting in the db the new objects. But when a remove the cascade attribute, this doesn't happend. It's very useful using the cascade attribute, so I'd like to know if I'm doing something wrong.

Thanks,
Martin.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 4:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what i understand is that you're trying to use long session per application pattern (several httprequest + a global commit).
The good point is that you've notices the need to set flushmode to NEVER.

The bad point is that it seems you're modifying detached instance.
IMO, session per application pattern has to be used when you don't want to manage detached instance.

So, i must recommend you to use session.lock(detachedObject, LockMode.NONE) to associate an unmodified detached instance, then you can change properties if you want and load lazy associations.

Only use session per application pattern if you're able to really define the start and the end of an application transaction. These kind of transaction shouldn't be too long.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.