-->
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.  [ 8 posts ] 
Author Message
 Post subject: Struggling to make Hibernate work
PostPosted: Sun Oct 02, 2005 10:23 pm 
Newbie

Joined: Sun Oct 02, 2005 9:58 pm
Posts: 7
Location: Brisbane
Hibernate version: 3.0

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="connection.datasource">java:comp/env/jdbc/focus_pancakes</property>
        <property name="show_sql">false</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Update database schema on startup -->
        <property name="hbm2ddl.auto">update</property>
       
        <!-- Mapping files -->
        <mapping resource="com/pancakes/website/controller/form/Condition.hbm.xml"/>
        <mapping resource="com/pancakes/website/controller/form/Menu.hbm.xml"/>
        <mapping resource="com/pancakes/website/controller/form/Review.hbm.xml"/>
        <mapping resource="com/pancakes/website/controller/form/User.hbm.xml"/>
        <mapping resource="com/pancakes/website/controller/form/Section.hbm.xml"/>
        <mapping resource="com/pancakes/website/controller/form/Category.hbm.xml"/>

    </session-factory>
</hibernate-configuration>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

    <class name="com.pancakes.website.controller.form.SectionForm" table="Sections">
        <id name="sid">
            <generator class="native"/>
        </id>
        <property name="section"/>
        <property name="seq" type="int"/>
        <set name="menuitems" inverse="true" cascade="all-delete-orphan">
            <key column="sid" on-delete="noaction"/>
            <one-to-many class="com.pancakes.website.controller.form.MenuForm" not-found="ignore"/>
        </set>
    </class>
   
</hibernate-mapping>


Code:
<?xml version="1.0" encoding="UTF-8"?>

<web-app    xmlns="http://java.sun.com/xml/ns/j2ee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
            version="2.4">
  <display-name>Pancakes at the Manor</display-name>
  <description>Pancakes at the Manor</description>
  <filter>
    <filter-name>HibernateFilter</filter-name>
    <filter-class>com.pancakes.website.HibernateFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HibernateFilter</filter-name>
    <servlet-name>*.do</servlet-name>
  </filter-mapping>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/config/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>
            30
        </session-timeout>
  </session-config>
  <welcome-file-list>
    <welcome-file>
            index.jsp
        </welcome-file>
  </welcome-file-list>
</web-app>


Code between sessionFactory.openSession() and session.close():

Code:
package com.pancakes.website;

import org.hibernate.*;
import org.hibernate.cfg.Configuration;


public class HibernateUtil {
   
    private static final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    private static final ThreadLocal threadSession = new ThreadLocal();
    private static final ThreadLocal threadTransaction = new ThreadLocal();
   
    public static Session getSession() {
        Session s = (Session) threadSession.get();
        // Open a new Session, if this thread has none yet
        try {
            if (s == null) {
                s = sessionFactory.openSession();
                threadSession.set(s);
            }
        } catch (HibernateException ex) {
            throw new HibernateException(ex);
        }
        return s;
    }
   
    public static void closeSession() {
        try {
            Session s = (Session) threadSession.get();
            threadSession.set(null);
            if (s != null && s.isOpen())
                s.close();
        } catch (HibernateException ex) {
            throw new HibernateException(ex);
        }
    }
   
    public static void beginTransaction() {
        Transaction tx = (Transaction) threadTransaction.get();
        try {
            if (tx == null) {
                tx = getSession().beginTransaction();
                threadTransaction.set(tx);
            }
        } catch (HibernateException ex) {
            throw new HibernateException(ex);
        }
    }
   
    public static void commitTransaction() {
        Transaction tx = (Transaction) threadTransaction.get();
        try {
            if ( tx != null && !tx.wasCommitted()
                && !tx.wasRolledBack() )
                tx.commit();
            threadTransaction.set(null);
        } catch (HibernateException ex) {
            rollbackTransaction();
            throw new HibernateException(ex);
        }
    }
   
    public static void rollbackTransaction() {
        Transaction tx = (Transaction) threadTransaction.get();
        try {
            threadTransaction.set(null);
            if ( tx != null && !tx.wasCommitted()
                && !tx.wasRolledBack() ) {
                tx.rollback();
            }
        } catch (HibernateException ex) {
            throw new HibernateException(ex);
        } finally {
            closeSession();
        }
    }
}               


Code:
package com.pancakes.website;

import java.io.IOException;
import javax.servlet.*;


/**
*
* @author Murray
*/
public class HibernateFilter implements Filter {
   
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain)
            throws IOException, ServletException {

        // There is actually no explicit "opening" of a Session, the
        // first call to HibernateUtil.beginTransaction() in control
        // logic (e.g. use case controller/event handler, or even a
        // DAO factory) will get a fresh Session.
        try {
            chain.doFilter(request, response);

            // Commit any pending database transaction.
            HibernateUtil.commitTransaction(); 

        } catch (RuntimeException ex) {
            HibernateUtil.rollbackTransaction(); // Also closes the Session 
            // Just rollback and let others handle the exception, e.g. for display
            throw ex;

        } finally {
            // No matter what happens, close the Session.
            HibernateUtil.closeSession();
        }
    }

    public void destroy() {
    }
}


Code:
package com.pancakes.website.controller.action;

import com.pancakes.website.Focus;
import com.pancakes.website.HibernateUtil;
import com.pancakes.website.controller.form.SectionForm;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
*
* @author Murray
*/
public class SectionDelete extends Action {
   
    /** Creates a new instance of MenuDelete */
    public SectionDelete() {
        super();
    }
   
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                HttpServletRequest request, HttpServletResponse response) {
       
        String szsid = request.getParameter("sid");
        Integer sid = Focus.string2Integer(szsid);
        Session session = HibernateUtil.getSession();
        Transaction tx = session.beginTransaction();
        SectionForm sf = (SectionForm) session.get(SectionForm.class, sid);
        if (sf != null)
            session.delete(sf);
        List result = session.createQuery("from com.pancakes.website.controller.form.SectionForm order by seq").list();
        request.setAttribute(SectionForm.listName, result);
        return mapping.findForward("Next");
    }
}


Full stack trace of any exception that occurs:

Code:
3/10/2005 11:43:04 org.apache.struts.action.RequestProcessor processException
WARNING: Unhandled Exception thrown: class org.hibernate.exception.GenericJDBCException
3/10/2005 11:43:04 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
org.hibernate.exception.GenericJDBCException: could not execute query
        at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
        at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.loader.Loader.doList(Loader.java:1596)
        at org.hibernate.loader.Loader.list(Loader.java:1577)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
        at com.pancakes.website.controller.action.SectionAction.execute(SectionAction.java:40)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:534)


Name and version of the database you are using:

MySQL 4.1

Problems:

Hi folks

Sorry to land all of this stuff but I've been struggling for about a week to get Hibernate working with the Struts filter thing. I had Hibernate working when I started and closed a session within an Action class but suffered the problem of accessing data objects after the session was closed. So I tried to implement filtering.

I have looked at numerous versions of HibernateUtils and HibernateFilter code and they all seem a little different. The Hibernate reference document gives a sample but this is not related to a servlet filter. The CaveatEmptor example looks entirely different and fails to implement functions required in other HibernateUtils, like get(), commit(), etc. I hunted on Google and found more versions but still they differed from the previous versions I had checked through.

I have also read through the majority of 'Hibernate in Action' and even this document gives cut down examples that don't include all of the code bits required to make the application work. When I check the source code referenced by the document it differs.

Anyways, I'm struggling.

Currently my application will read and display stuff from the database but when I try to delete a row from the 'Sections' table the row is not removed and I get a JDBC error. The record remains in some locked state until I restart my database server. I'm thinking this problem may be related to the cascade="all-delete-orphan" option I am using (as this was recently added). I coded this while reading through the 'Hibernate in Action' documentation so not quite sure what I might have done wrong.

I would really appreciate it if somebody could take a quick look over my config files and the two java files above and let me know if anything is really out of whack.

TIA
Murray


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 10:25 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You are missing a nested exception there, this is not the cause.


Top
 Profile  
 
 Post subject: The nested exception
PostPosted: Sun Oct 02, 2005 10:29 pm 
Newbie

Joined: Sun Oct 02, 2005 9:58 pm
Posts: 7
Location: Brisbane
Stack trace from the nested exception - not sure it helps much...

Code:
** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: Software caused connection abort: socket write error

STACKTRACE:

java.net.SocketException: Software caused connection abort: socket write error
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:66)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:124)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2616)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2547)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1512)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2385)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2306)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1877)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1722)
        at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
        at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
        at org.hibernate.loader.Loader.doQuery(Loader.java:391)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
        at org.hibernate.loader.Loader.doList(Loader.java:1593)
        at org.hibernate.loader.Loader.list(Loader.java:1577)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
        at com.pancakes.website.controller.action.SectionAction.execute(SectionAction.java:40)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:534)


** END NESTED EXCEPTION **


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 10:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Database/driver issue, not Hibernate related.


Top
 Profile  
 
 Post subject: And another error
PostPosted: Sun Oct 02, 2005 10:39 pm 
Newbie

Joined: Sun Oct 02, 2005 9:58 pm
Posts: 7
Location: Brisbane
Thanks for your quick response Christian.

The database driver is the standard Connecter/J as recommended by the team at MySQL. As mentioned above it was working (despite the closed session in view error) when opening and closing session in the action class.

This one after deleting and adding a new section. I think the delete has left something behind causing the add to fail. See the generated SQL below.

Code:
root cause

org.hibernate.exception.LockAcquisitionException: could not insert: [com.pancakes.website.controller.form.SectionForm]
   org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:77)
   org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1777)
   org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2178)
   org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
   org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
   org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:240)
   org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
   org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
   org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
   org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
   org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
   com.pancakes.website.controller.action.SectionAdd.execute(SectionAdd.java:46)
   org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


And some generated SQL

Code:
Hibernate: select menuform0_.mid as mid, menuform0_.title as title1_, menuform0_.description as descript3_1_, menuform0_.price as price1_, menuform0_.rating as rating1_, menuform0_.dateFrom as dateFrom1_, menuform0_.dateTo as dateTo1_, menuform0_.imagename as imagename1_, menuform0_.sid as sid1_, menuform0_.catid as catid1_ from Menu menuform0_
Hibernate: select userform0_.uid as uid, userform0_.email as email4_, userform0_.name as name4_, userform0_.password as password4_, userform0_.touched as touched4_ from User userform0_ where userform0_.email=? and userform0_.password=?
Hibernate: select sectionfor0_.sid as sid, sectionfor0_.section as section5_, sectionfor0_.seq as seq5_ from Sections sectionfor0_ order by sectionfor0_.seq
Hibernate: select sectionfor0_.sid as sid0_, sectionfor0_.section as section5_0_, sectionfor0_.seq as seq5_0_ from Sections sectionfor0_ where sectionfor0_.sid=?
Hibernate: select menuitems0_.sid as sid1_, menuitems0_.mid as mid1_, menuitems0_.mid as mid0_, menuitems0_.title as title1_0_, menuitems0_.description as descript3_1_0_, menuitems0_.price as price1_0_, menuitems0_.rating as rating1_0_, menuitems0_.dateFrom as dateFrom1_0_, menuitems0_.dateTo as dateTo1_0_, menuitems0_.imagename as imagename1_0_, menuitems0_.sid as sid1_0_, menuitems0_.catid as catid1_0_ from Menu menuitems0_ where menuitems0_.sid=?
Hibernate: delete from Sections where sid=?
Hibernate: select sectionfor0_.sid as sid, sectionfor0_.section as section5_, sectionfor0_.seq as seq5_ from Sections sectionfor0_ order by sectionfor0_.seq
Hibernate: select sectionfor0_.sid as sid, sectionfor0_.section as section5_, sectionfor0_.seq as seq5_ from Sections sectionfor0_ order by sectionfor0_.seq
Hibernate: insert into Sections (section, seq) values (?, ?)
Hibernate: select sectionfor0_.sid as sid, sectionfor0_.section as section5_, sectionfor0_.seq as seq5_ from Sections sectionfor0_ order by sectionfor0_.seq
Hibernate: select menuitems0_.sid as sid1_, menuitems0_.mid as mid1_, menuitems0_.mid as mid0_, menuitems0_.title as title1_0_, menuitems0_.description as descript3_1_0_, menuitems0_.price as price1_0_, menuitems0_.rating as rating1_0_, menuitems0_.dateFrom as dateFrom1_0_, menuitems0_.dateTo as dateTo1_0_, menuitems0_.imagename as imagename1_0_, menuitems0_.sid as sid1_0_, menuitems0_.catid as catid1_0_ from Menu menuitems0_ where menuitems0_.sid=?
Hibernate: delete from Sections where sid=?
Hibernate: select sectionfor0_.sid as sid, sectionfor0_.section as section5_, sectionfor0_.seq as seq5_ from Sections sectionfor0_ order by sectionfor0_.seq
Hibernate: insert into Sections (section, seq) values (?, ?)
3/10/2005 12:33:42 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1205, SQLState: HY000
3/10/2005 12:33:42 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Lock wait timeout exceeded; try restarting transaction
3/10/2005 12:33:42 org.apache.struts.action.RequestProcessor processException
WARNING: Unhandled Exception thrown: class org.hibernate.exception.LockAcquisitionException
3/10/2005 12:33:42 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
org.hibernate.exception.LockAcquisitionException: could not insert: [com.pancakes.website.controller.form.SectionForm]
        at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:77)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1777)
        at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2178)
        at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
        at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:240)
        at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
        at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
        at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
        at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
        at com.pancakes.website.controller.action.SectionAdd.execute(SectionAdd.java:46)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:534)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 10:51 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Again, this is not the real exception. Sorry, but all that is happening is that your driver can't write to the network socket to the database. Nothing Hibernate can do about that. If you are not sure what is going wrt your Hibernate code, add a few debug statements and check the session and transaction interaction. Your code looks ok.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 10:55 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And check the comments on http://hibernate.org/43.html for Struts, there were some issues with interception of *.do and filters. Since I don't use Struts or recommend it, I don't know the details. Checkout WebWork if you need a Struts-like-framework-done-right.


Top
 Profile  
 
 Post subject: The solution
PostPosted: Mon Oct 03, 2005 12:40 am 
Newbie

Joined: Sun Oct 02, 2005 9:58 pm
Posts: 7
Location: Brisbane
I posted a link to this question on the Struts list. The answer turned out to be my filter specification, server-name of *.do doesn't work well.

Have made this change and it now seems to be behaving much better.

Thanks for your help Christian.


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