-->
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.  [ 5 posts ] 
Author Message
 Post subject: what is the diff bet session.flush and tx.commit
PostPosted: Fri Jun 25, 2004 5:04 pm 
Newbie

Joined: Mon Jun 21, 2004 11:56 am
Posts: 8
does session.flush() commit the changes to the DB????

what i am trying to do is, delete a set of records and then insert another set with the same primary key. if i don't do a session.flush() after the delete (i am using session.delete(String, Object[], Type[])), i get a primary key violation. if i do a session.flush(), everything works fine, but i just want to make sure, that the whole thing is executed in one transaction.

here is the sample code:

Code:
session = getSessionFactory().openSession();
transaction = session.beginTransaction();
compatiblityDAO = new CompatiblityDAO(session);

//delete "TO" Program
compatiblityDAO.deleteCompatibilityTypes(toMarket, toSystemId);

session.flush(); //if i dont do this i get primary key violation

type= null;

//insert from "FROM" Program
for (Iterator it = fromTypes.iterator(); it.hasNext();) {
    .... some processing   
     compatiblityDAO.insertCompatibilityType(type);
}
transaction.commit();


Here is the delete and insert methods of compatibilityDAO

Code:
private String SELECT_ALL_COMPATIBILITY_TYPES =
      "from com.dcx.slsmkt.upic.rules.bo.CompatibleType as comp where comp.market= :market and comp.programId = :programId";

public void deleteCompatibilityTypes(String market, int systemId) throws RulesException {
      try {
         session.delete(SELECT_ALL_COMPATIBILITY_TYPES, new Object[] {market, new Integer(systemId)}, new Type[] {Hibernate.STRING, Hibernate.INTEGER});
         
      } catch (HibernateException e) {
         log.error(e);
         throw new RulesException(e);
      }          
   }

public void insertCompatibilityType(CompatibleType compType) throws RulesException {
      try {
         getSession().save(compType);
      } catch (HibernateException e) {
         log.error(e);
         throw new RulesException(e);
      }          
   }


Any help would be greatly appreciated. Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 5:06 pm 
Newbie

Joined: Mon Jun 21, 2004 11:56 am
Posts: 8
i know my mappings are right, becoz, seperate inserts/updates, selects and deletes are working. anyway here it is.

Code:
<class name="com.dcx.slsmkt.upic.rules.bo.CompatibleType" table="S.SADCPTP">
       <composite-id>
            <key-property name="market" column="C_MKT_INCTV" type="string" />
            <key-property name="programId" column="I_SYS_INCTV" type="int" />
            <key-property name="fleetRetail" column="C_FLET_RETL" type="string" />
            <key-property name="targetType" column="C_PGM_HIER" type="string" />
       </composite-id>
      
      <property name="status">
            <column name="C_COMP" sql-type="char(1)" not-null="true"/>
        </property>      

        <property name="lastUser">
            <column name="I_USER" sql-type="char(10)" not-null="true"/>
        </property>
       
        <property name="stamp">
            <column name="T_UPD" sql-type="timestamp" not-null="true"/>
        </property>
       
    </class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 5:08 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
My understanding is:

flush actually causes Hibernate to issue all its pending SQL queries to the database. this is independent of actually calling sql "COMMIT;"

commit does a flush and then a sql "COMMIT;"

I guess if you are using autocommit in your db then the two have the same result.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 26, 2004 12:20 pm 
Newbie

Joined: Mon Jun 21, 2004 11:56 am
Posts: 8
cool! thanx for the reply! I guess that solves my issue.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 27, 2004 12:36 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
commit executes flush just before "really" commiting changes IF flushmode = auto (which is the default value)

_________________
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.  [ 5 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.