-->
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.  [ 6 posts ] 
Author Message
 Post subject: Parent-Child List Problems
PostPosted: Thu Oct 19, 2006 12:08 pm 
Newbie

Joined: Thu Oct 19, 2006 11:28 am
Posts: 4
Hello everyone,

I am having problems persisting using detached parent-child Lists. Whenever I attempt to get() the parent object from the database and add a Child object, I am unable to persist the objects (see below). The system just hangs until it finally times out. Why is this occuring, how can I remedy it, and what am I missing?

Thanks in advance,
Mike M.

Code:
// Test ProjectOrder
   ProjectOrder po = manager.getProjectOrderbyProjectID(id);
         
   // Dummy task
         
   Task t = new Task();
   List<Task> l = new ArrayList<Task>();
         
   /* This made it work once
   po = new ProjectOrder();
   po.setShortdesc("New Project");
    */      
   
         
   t.setTask("get it working");
   t.setUsername("joe");
   
   po.addTask(t);
   
   //saveOrUpdate()
   manager.modifyProjectOrder(po); // Error happens here





Hibernate version: v3.1.3

ProjectOrder.hbm.xml:
Code:
  <class name="ProjectOrder" table="ProjectOrder" lazy="false" >
   <id name="projectid" column="projectid" type="integer" unsaved-value="0">
      <generator class="increment" />
   </id>
   <property name="shortdesc" />
   <property name="deptorgname" />
   <property name="name" />
    <list name="tasks" inverse="false" cascade="all,delete-orphan" lazy="false">
       <key column="projectid" not-null="true" update="false" />
   <index column="taskidx" />
   <one-to-many class="Task" />
    </list>
  </class>


ProjectOrder.hbm.xml:
Code:
  <class name="ProjectOrder" table="ProjectOrder" lazy="false" >
   <id name="projectid" column="projectid" type="integer" unsaved-value="0">
      <generator class="increment" />
   </id>
   <property name="shortdesc" />
   <property name="deptorgname" />
   <property name="name" />
    <list name="tasks" inverse="false" cascade="all,delete-orphan" lazy="false">
       <key column="projectid" not-null="true" update="false" />
   <index column="taskidx" />
   <one-to-many class="Task" />
    </list>
  </class>

ProjectOrder.hbm.xml:
Code:
<class name="Task" table="Task" lazy="false">
   <id name="taskid" column="taskid" type="integer" unsaved-value="0" >
      <generator class="increment" />
   </id>
   <many-to-one name="projectOrder"
       column="projectid" not-null="true"
       insert="false" update="false" />
   <property name="username" type="string" />
   <property name="task" type="string" />
  </class>




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


Full stack trace of any exception that occurs:
Code:
Oct 19, 2006 8:47:46 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet asic.admin.AdminServlet threw exception
org.hibernate.exception.DataException: Could not execute JDBC batch update
        at asic.admin.HibernateAdminManager.modifyProjectOrder(HibernateAdminManager.java:76)
        at asic.admin.AssignCommand.execute(AssignCommand.java:127)
        at asic.admin.AdminServlet.doPost(AdminServlet.java:57)
        at asic.admin.AdminServlet.doGet(AdminServlet.java:32)
        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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
        at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:693)
        at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:660)
        at org.apache.jsp.admin.index_jsp._jspService(index_jsp.java:147)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
        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:213)
        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:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        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:595)
Caused by: java.sql.SQLException
        ... 41 more
Oct 19, 2006 8:47:46 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.hibernate.exception.DataException: Could not execute JDBC batch update
        at asic.admin.HibernateAdminManager.modifyProjectOrder(HibernateAdminManager.java:76)
        at asic.admin.AssignCommand.execute(AssignCommand.java:127)
        at asic.admin.AdminServlet.doPost(AdminServlet.java:57)
        at asic.admin.AdminServlet.doGet(AdminServlet.java:32)
        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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
        at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:693)
        at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:660)
        at org.apache.jsp.admin.index_jsp._jspService(index_jsp.java:147)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
        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:213)
        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:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        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:595)




The generated SQL (show_sql=true):
Code:
Hibernate:
    select
        projectord0_.projectid as projectid0_0_,
        projectord0_.shortdesc as shortdesc0_0_,
        projectord0_.deptorgname as deptorgn3_0_0_,
        projectord0_.name as name0_0_
    from
        ProjectOrder projectord0_
    where
        projectord0_.projectid=?
Hibernate:
    select
        tasks0_.projectid as projectid1_,
        tasks0_.taskid as taskid1_,
        tasks0_.taskidx as taskidx1_,
        tasks0_.taskid as taskid4_0_,
        tasks0_.projectid as projectid4_0_,
        tasks0_.username as username4_0_,
        tasks0_.task as task4_0_
    from
        Task tasks0_
    where
        tasks0_.projectid=?
Project order desc is: test
Hibernate:
    select
        max(taskid)
    from
        Task
Hibernate:
    insert
    into
        Task
        (username, task, projectid, taskidx, taskid)
    values
        (?, ?, ?, ?, ?)

Hangs here


Debug level Hibernate log excerpt:
Code:
Oct 19, 2006 8:47:46 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at asic.admin.HibernateAdminManager.modifyProjectOrder(HibernateAdminManager.java:74)



Last edited by MikeM on Thu Oct 19, 2006 12:16 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 12:15 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Can you post the addTask() method of the ProjectOrder class?


Top
 Profile  
 
 Post subject: addTask
PostPosted: Thu Oct 19, 2006 12:21 pm 
Newbie

Joined: Thu Oct 19, 2006 11:28 am
Posts: 4
Code:
class ProjectOrder {

// ...

public void addTask(Task task) {
      task.setProjectOrder(this);
      _tasks.add(task);
   }

// ...

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 12:33 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Here is how I do my addTask, with very similar mappings (Project 0..*-> Tasks), looks pretty similar except for the null safes.

Code:
    public void addTask(Task task) throws InfrastructureException {
        if (task != null) {
            if (this.getTasks() == null) {
                setTasks(new ArrayList<Task>());
            }
            this.getTasks().add(task);
            task.setProject(this);
        } else {
            throw new DomainCollectionException(
                    "Error adding task to project");
        }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 11:06 am 
Newbie

Joined: Wed Aug 03, 2005 6:49 pm
Posts: 9
Another thing.

1. Use sets for parent child relations. There is no way the same task can exist in the same project twice I think. If thats not the case use Bag instead.

2. In your case I believe inverse on the ProjectOrder side should be set to inverse true

3. When inverse is set to true, Hibernate does not use the sort column and the list turns into a bag.


Top
 Profile  
 
 Post subject: Cannot persist
PostPosted: Mon Oct 23, 2006 3:40 am 
Newbie

Joined: Thu Oct 19, 2006 11:28 am
Posts: 4
Strange... now I am using the exact same code and I cannot get objects to persist. First it will run an ill-fated update to a non-existent task, then on the second attempt it will try to update the ProjectOrder and outputs, "Could not execute JDBC batch update." What is going on here?


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