-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate not committing/updating to database.
PostPosted: Tue Aug 30, 2011 11:44 am 
Newbie

Joined: Tue Aug 30, 2011 10:42 am
Posts: 4
I have search for solutions and I cant find any, I have tried just about everything I can and nothing works.

I have this code...

Code:
@Override
   public void updateUser(UserModel model) {
      
      Session session = sessionFactory.getCurrentSession();
      
      session.saveOrUpdate(model);
   }


where sessionFactory is a spring managed bean, and I am using a HibernateFilter to OpenSessionInView, and using HibernateTransaction management proxy to manage the transactions.

I have tried everything in this function, update, save, merge, using my own transactions where I begin the transaction and commit it in the same function call, I have flushed the session, and closed the session, and nothing works, hibernate will not write update information to the database.

When I unit test this DAO there isnt any problems, it works fine, the test and the spring server use the same hibernate configuration file. The UserModel is first retrieved from the database, some work is done on it, then its passed to this update function, where I am updating the last login time which is what I am expecting to be updated, and it just will not commit the changes, I have been on this for atleast 2 days now. Is there any reason why this wouldnt work?


Top
 Profile  
 
 Post subject: Re: Hibernate not committing/updating to database.
PostPosted: Wed Aug 31, 2011 3:52 am 
Newbie

Joined: Tue Aug 30, 2011 10:42 am
Posts: 4
I should probably delete this post but doesnt look like I can.

I cant believe this, after 2-3 days working on this, what the problem ended up being was nothing to do with the server. It was the permissions on the database! Agh for some reason "Grant" wasnt ticked on the permissions...... ugh


Top
 Profile  
 
 Post subject: Re: Hibernate not committing/updating to database.
PostPosted: Wed Aug 31, 2011 4:23 am 
Newbie

Joined: Tue Aug 30, 2011 10:42 am
Posts: 4
scratch that, its still broken, ugh... I dont know how but somehow 1 update managed to get through, but now its totally broken again


Top
 Profile  
 
 Post subject: Re: Hibernate not committing/updating to database.
PostPosted: Wed Aug 31, 2011 6:12 am 
Newbie

Joined: Tue Aug 30, 2011 10:42 am
Posts: 4
ok finally fixed!

needed to use the following transaction setup, the one I had before wasnt working

from http://static.springsource.org/spring/d ... e/orm.html
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

  <!-- SessionFactory, DataSource, etc. omitted -->

  <bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="mySessionFactory"/>
  </bean>
 
  <aop:config>
    <aop:pointcut id="productServiceMethods" expression="execution(* product.ProductService.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods"/>
  </aop:config>

  <tx:advice id="txAdvice" transaction-manager="myTxManager">
    <tx:attributes>
      <tx:method name="increasePrice*" propagation="REQUIRED"/>
      <tx:method name="someOtherBusinessMethod" propagation="REQUIRES_NEW"/>
      <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
    </tx:attributes>
  </tx:advice>

  <bean id="myProductService" class="product.SimpleProductService">
    <property name="productDao" ref="myProductDao"/>
  </bean>

</beans>



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.