Announcement Announcement Module
Collapse
No announcement yet.
Spring + hibernate can't delete, update, save Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + hibernate can't delete, update, save

    Hello everyone. I'm a newbie in Spring. I am Using Spring 2.5, Hibernate 3.2 and MySQL 5.1.32 (included in wamp 2.0)

    This is my allpicationContext.xml
    Code:
    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <property name="configLocation"
             value="classpath:hibernate.cfg.xml">
          </property>
       </bean>
       
       <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
           <property name="sessionFactory">
             <ref bean="sessionFactory"/>
          </property>
        </bean>
       
       <bean id="UsersDAO" class="com.smsapp.hibernate.UsersDAO">
          <property name="sessionFactory">
             <ref bean="sessionFactory" />
          </property>
       </bean>
    <bean id="LocationDAO" class="com.smsapp.hibernate.LocationDAO">
          <property name="sessionFactory">
             <ref bean="sessionFactory" />
          </property>
       </bean>
    Users.java, UsersDAO.java, Location.java and LocationDAO.java... etc. are generated with MyEclipse 7.0 Hibernate Reverse-Engineering Tools

    I tried a simple delete with this code in LocationDAO.java
    Code:
    public static void main(String[] args) {
       ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
            LocationDAO loc = LocationDAO.getFromApplicationContext(ctx);
            System.out.println(loc.findById(3).getLocationName());
       loc.delete(loc.findById(3));
       }
    System.out.println returns the location name but I get this error:

    Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException : Hibernate operation: Could not execute JDBC batch update; uncategorized SQLException for SQL [delete from oms.location where id=?]; SQL state [41000]; error code [1205]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
    at org.springframework.jdbc.support.SQLStateSQLExcept ionTranslator.translate(SQLStateSQLExceptionTransl ator.java:124)
    at org.springframework.orm.hibernate3.HibernateAccess or.convertJdbcAccessException(HibernateAccessor.ja va:424)
    at org.springframework.orm.hibernate3.HibernateAccess or.convertHibernateAccessException(HibernateAccess or.java:410)
    at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:424)
    at org.springframework.orm.hibernate3.HibernateTempla te.executeWithNativeSession(HibernateTemplate.java :374)
    at org.springframework.orm.hibernate3.HibernateTempla te.delete(HibernateTemplate.java:842)
    at com.smsapp.hibernate.LocationDAO.removeRecord(Loca tionDAO.java:154)
    at com.smsapp.hibernate.LocationDAO.main(LocationDAO. java:161)
    Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
    at com.mysql.jdbc.PreparedStatement.executeBatchSeria lly(PreparedStatement.java:1666)
    at com.mysql.jdbc.PreparedStatement.executeBatch(Prep aredStatement.java:1082)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:48)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:246)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:237)
    at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:146)
    at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:298)
    at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1000)
    at org.springframework.orm.hibernate3.HibernateAccess or.flushIfNecessary(HibernateAccessor.java:390)
    at org.springframework.orm.hibernate3.HibernateTempla te.doExecute(HibernateTemplate.java:420)
    ... 4 more

    Only save(), delete(), and update(), doesn't work. It's very annoying, everyone just keeps telling me to restart the transaction, but that doesn't seems to be the problem. Anyone experienced the same problem?
Working...
X