-->
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: let hibernate loss feeling collection's change...how to do?
PostPosted: Tue Sep 13, 2011 3:26 am 
Newbie

Joined: Tue Sep 13, 2011 2:58 am
Posts: 1
hi,all
i need a demand that when hibernate flush changes to database ,i need some entity's collection don't be flushed。such as this a Execution with some variables,when Execution has been removed ,i need Hibernate don't modify the variables'S parent,don't set them parent is null.it get so many sql。。。。I don't love it :(。。。。so i want change this。。。i modify it like this:
create a new FlushEventListener ,copy the AbstractFlushingEventListener and DefaultAutoFlushEventListener in the it。add decision in the method of
Quote:
flushCollections(EventSource session)
,modify like this:
Code:
   private void flushCollections(EventSource session)
         throws HibernateException {

      log.trace("Processing unreferenced collections");

      List list = IdentityMap.entries(session.getPersistenceContext()
            .getCollectionEntries());
      int size = list.size();
      for (int i = 0; i < size; i++) {
         Map.Entry me = (Map.Entry) list.get(i);
         CollectionEntry ce = (CollectionEntry) me.getValue();
         if (!ce.isReached() && !ce.isIgnore()) {
            Collections.processUnreachableCollection(
                  (PersistentCollection) me.getKey(), session);
         }
      }

      // Schedule updates to collections:

      log.trace("Scheduling collection removes/(re)creates/updates");

      list = IdentityMap.entries(session.getPersistenceContext()
            .getCollectionEntries());
      size = list.size();
      ActionQueue actionQueue = session.getActionQueue();
      for (int i = 0; i < size; i++) {
         Map.Entry me = (Map.Entry) list.get(i);
         PersistentCollection coll = (PersistentCollection) me.getKey();
         CollectionEntry ce = (CollectionEntry) me.getValue();
                       [i][color=#FF0000]if (ce.getRole() != null && ce.getRole().indexOf("personal.shuaia") != -1){
            continue;   //modify here。don't generate the cats's change-sql
         }[/color][/i]
         if (ce.isDorecreate()) {
            session.getInterceptor().onCollectionRecreate(coll,
                  ce.getCurrentKey());
            actionQueue.addAction(new CollectionRecreateAction(coll, ce
                  .getCurrentPersister(), ce.getCurrentKey(), session));
         }
         if (ce.isDoremove()) {
            session.getInterceptor().onCollectionRemove(coll,
                  ce.getLoadedKey());
            actionQueue.addAction(new CollectionRemoveAction(coll, ce
                  .getLoadedPersister(), ce.getLoadedKey(), ce
                  .isSnapshotEmpty(coll), session));
         }
         if (ce.isDoupdate()) {
            session.getInterceptor().onCollectionUpdate(coll,
                  ce.getLoadedKey());
            actionQueue.addAction(new CollectionUpdateAction(coll, ce
                  .getLoadedPersister(), ce.getLoadedKey(), ce
                  .isSnapshotEmpty(coll), session));
         }

      }

      actionQueue.sortCollectionActions();

   }


BUT,I GET EXCEPTION whit this modify!!!!:(:(:(:(:(


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.