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: aession.save produce too many sql updates
PostPosted: Fri Mar 18, 2005 8:34 am 
Newbie

Joined: Tue Apr 06, 2004 9:15 am
Posts: 4
Hibernate version: 2.1.6 ( the same one integrated in Jboss AS 4.0.1sp1 )

Mapping documents:
Mapping use composite keys (id x beginDateTime x versionBegin )

( Note: versionBegin isn't hibernate version)

Name and version of the database you are using: Oracle 9i



Hi,
I have the following code:
Code:
      Session hsession = HibernateContext.getSession("java:/hibernate/TestSessionFactory");
      Transaction tx = hsession.beginTransaction();
      try
      {

         for (int i = 0; i < ObjectArrayValues.size(); i++)
         {
            int id = ((ObjectBean) ObjectArrayValues.get(i)).getID();
            Date beginDate = ((ObjectBean) vObjectArrayValues.get(i)).getBeginDateTime();


            Query q = hsession
                  .createQuery("from ObjectBean as cmv where " +
                          "cmv.id = :Id and " +
                          "cmv.beginDateTime <= :beginDateTime and " +
                          "cmv.versionEnd is null");

            q.setInteger("Id", id);
            q.setTimestamp("beginDateTime", beginDate);

            List lCmv = q.list();

            ObjectBean oBean = null;
            if (lCmv.size() != 0)
               oBean = (ObjectBean) lCmv.get(0);


            if (oBean != null)
            {
               oBean.setVersionEnd(new Date());
               hsession.update(oBean);
            }

            ObjectBean oValue = (ObjectBean) ObjectArrayValues.get(i);
            oArrayValues.setVersionBegin(new Date());
            oArrayValues.setVersionEnd(null);
            hsession.save(oValue);
            hsession.flush();

         }
         hsession.flush();
         tx.commit();
      }
      catch (HibernateException e)
      {
         log.error("Error:", e);
         tx.rollback();
      }




when I do:
hsession.save(oValue);
hsession.flush();

hibernate produce:
1º iteration: 1 insert and 2 update with same values
2º iteration: 1 insert and 4 updates with same values
3º iteration: 1 insert and 6 updates with same values

why hibernate produce so many updates when I only want an Insert ??


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.