Results 1 to 9 of 9

Thread: Data does not commit.

  1. #1
    Join Date
    Sep 2004
    Location
    Bangalore / India
    Posts
    7

    Default Data does not commit.

    Hi ,

    My app uses Struts(1.4) + Spring(1.1.1) + Hibernate(2.1)
    I have noticed that whenever any insert or update is done ,
    the data does not get commited ,

    following is the configuration details

    1. I use contextLoaderPlugin to integrate Struts and Spring

    <plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="contextConfigLocation"
    value="/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml"/>
    </plug-in>

    2. I have following configuration for hibernate and Spring
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="mappingResources">
    <list>
    <!--<value>org/med/common/User.hbm.xml</value> -->
    <value>org/med/common/Responsibilities.hbm.xml</value>
    <value>org/med/common/core/model/Product.hbm.xml</value>
    <value>org/med/common/core/model/Order.hbm.xml</value>
    <value>org/med/common/core/model/OrderItem.hbm.xml</value>
    </list>
    </property>

    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.O racleDialect</prop>
    <prop key="hibernate.connection.driver_class">oracle.jdb c.driver.OracleDriver</prop>
    <prop key="hibernate.connection.username">user</prop>
    <prop key="hibernate.connection.password">password</prop>
    <prop key="hibernate.connection.url">jdbc:oracle:thin:@l ocalhost:1521:sid</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>


    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="myTransactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property>
    </bean>

    <!-- ***** ORDER SERVICE *****-->
    <bean id="orderService" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="myTransactionManager"/></property>
    <property name="target"><ref local="orderDAO"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly,-OrderException</prop>
    <prop key="save*">PROPAGATION_REQUIRED,-OrderException,-OrderMinimumAmountException</prop>
    <prop key="create*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <!-- Order DAO object: Hibernate implementation -->
    <bean id="orderDAO" class="org.med.common.core.dao.OrderDAO" singleton="false">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property>
    </bean>

    3. In my hibernate DAO I do followng thing


    public void createOrder(Order order){
    getHibernateTemplate().saveOrUpdate(order);
    }



    When I run my application , I see following sql's being generate

    Hibernate: insert into beta_orders (order_date, price_total, id) values (?, ?, ?)
    Hibernate: insert into beta_order_items (amount, price, order_id, product_id, id) values (?, ?, ?, ?, ?)
    Hibernate: update beta_products set name=?, price=?, amount=? where id=?


    The problem is the data gets reflected in my DB once I shutdown the server,
    I guess Iam missing out some basic parameter in my configuration files like auto commit.

    Thanks
    -Hari

  2. #2
    Join Date
    Sep 2004
    Posts
    50

    Default

    If your data is being commited to the database when the server is shutdown it would appear everything is okay and you just need a getHibernateTemplate().flush(); after the getHibernateTemplate().saveOrUpdate(order); statement to force hibernate to commit the data.

  3. #3
    Join Date
    Sep 2004
    Location
    Bangalore / India
    Posts
    7

    Default

    but there isn't any
    getHibernateTemplate().flush();
    method..
    Hari

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Hari,

    getHibernateTemplate().flush() does exist in Spring since 1.1. Are you sure you are using version 1.1.1?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  5. #5
    Join Date
    Sep 2004
    Location
    Bangalore / India
    Posts
    7

    Default

    Omar,

    yes you were right , I had reference to old spring jars in eclipse , now I have set it to 1.1.

    I have added following line

    getHibernateTemplate().saveOrUpdate(order);
    >getHibernateTemplate.flush();

    but still the data does not commit,

    I guess we need not even add those lines , most of the sample applciations that I have seen , I don't see flush being called at all.

    any clues...

    -Hari
    Hari

  6. #6
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Hari,

    Indeed, you do not need to use flush in this case.
    can you show the piece of configuration where you connect your DAO to your Service?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  7. #7
    Join Date
    Sep 2004
    Location
    Bangalore / India
    Posts
    7

    Default

    here is the complete DAO code

    public class OrderDAO extends HibernateDaoSupport {
    public Product findProductByName(String productID){
    return (Product) getHibernateTemplate().get(Product.class, productID);
    }

    public void createOrder(Order order){
    getHibernateTemplate().saveOrUpdate(order);
    //getHibernateTemplate().flush();
    }
    }

    I have added all the configuration details in my initial post,

    -Hari
    Hari

  8. #8
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    I am sorry, I didn't read your initial post carrefuly.
    I can see that you configure your DataSource using Hibernate
    Code:
    <prop key="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</prop> 
    <prop key="hibernate.connection.username">user</prop> 
    <prop key="hibernate.connection.password">password</prop> 
    <prop key="hibernate.connection.url">jdbc&#58;oracle&#58;thin&#58;@localhost&#58;1521&#58;sid</prop>
    Could you use DBCP to configure the DataSource and inject it inside your sessionFactory?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  9. #9
    Join Date
    Sep 2004
    Location
    Bangalore / India
    Posts
    7

    Default

    ok , it works now!!

    I have injected datasources properties like this

    <property name="dataSource"><ref local="dataSource"/></property>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName"><value>oracle.jdbc.driver.O racleDriver</value></property>
    <property name="url"><value>jdbc:oracle:thin:@localhost:1521 :dmc</value></property>
    <property name="username"><value>medicom</value></property>
    <property name="password"><value>medicom</value></property>
    </bean>



    now the data gets commited,

    but what's wrong with the way I was doing things ...
    Hari

Similar Threads

  1. Connection closed after transaction commit
    By alirussi in forum Data
    Replies: 4
    Last Post: Dec 17th, 2011, 06:41 AM
  2. Replies: 2
    Last Post: Oct 18th, 2005, 10:08 AM
  3. Replies: 1
    Last Post: Aug 31st, 2005, 04:18 AM
  4. Multiple Data Sources + Hibernate + Spring
    By joeserel in forum Data
    Replies: 2
    Last Post: May 18th, 2005, 09:22 AM
  5. injecting complex configuration data
    By fox9 in forum Container
    Replies: 2
    Last Post: Feb 25th, 2005, 07:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •