-->
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: update problem with many-to-many relationship
PostPosted: Fri Mar 05, 2004 1:01 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 10:39 pm
Posts: 44
I have a class representing product categories and then the class that represents the product.

The category and product has a many-to-many association.

Here is my mapping for the product category class. This is not a bidrectional relationship so my product does not have a property to store the category references it belongs to. Might this be a problem?
Code:
<set
            name="elements"
            table="manytomany_elements"
            lazy="false"
            inverse="false"
            cascade="all"
            sort="unsorted"
        >

              <key
                  column="relationshipID"
              />

              <many-to-many
                  class="com.forisent.framework.productManager.store.entity.SellableProduct"
                  column="productID"
                  outer-join="auto"
              />

        </set>


Here is my persistence code:
Code:
   public Object persist(Object obj) throws PersistenceException{
         
      Session session = null;
      log.info("Persisting object: " + obj.getClass().toString());
      try{
         session = getSession();
                  
         try{
            session.saveOrUpdate(obj);   
         }catch(HibernateException e){
            log.error("Rolling Back Persist Operation");
         }
         session.flush();
                  
      }catch(HibernateException e){
         throw new PersistenceException(e.getMessage(), e);
      }finally{
         try{
            closeSession();
         }catch(HibernateException e){
            throw new PersistenceException(e.getMessage(), e);
         }
      }
      return obj;   
   }


When I try to persist the relationship, I get this error:
Code:
com.forisent.framework.common.exception.PersistenceException: Could not execute JDBC batch update


The data is being persisted but I get all these exceptions for each time I try to persist the many-to-many relationship.

Any ideas what I have done wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 1:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Next time you post, look in that huge red box. See this line:

Quote:
the full stack trace of any exception that occurs


Please read this before posting again:

http://www.hibernate.org/ForumMailingli ... AskForHelp


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 1:39 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 10:39 pm
Posts: 44
ok gavin,

guilty as charged....

Code:
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:125)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2311)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2265)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
   at com.forisent.framework.productManager.store.PersistenceManager.persist(PersistenceManager.java:82)
   at com.forisent.framework.productManager.productOrganizer.store.factory.PersistanceManagerTest.testPersistOneRelationship(PersistanceManagerTest.java:82)
   at java.lang.reflect.Method.invoke(Native Method)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.apache.cactus.server.runner.ServletTestRunner.run(ServletTestRunner.java:313)
   at org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody0(ServletTestRunner.java:209)
   at org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody1$advice(ServletTestRunner.java:158)
   at org.apache.cactus.server.runner.ServletTestRunner.doGet(ServletTestRunner.java)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
   at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
   at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
   at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
   at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
   at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
   at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
   at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
   at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114)
   at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
   at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
   at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
   at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
   at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
Caused by: java.sql.BatchUpdateException: General error,  message from server: "Column 'productID' cannot be null"
   at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1404)
   at com.mysql.jdbc.jdbc2.optional.StatementWrapper.executeBatch(StatementWrapper.java:597)
   at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeBatch(WSJdbcStatement.java:341)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
   ... 48 more


here is the entire exception. The key being this line:
Code:
Caused by: java.sql.BatchUpdateException: General error,  message from server: "Column 'productID' cannot be null"


...however, I still can't understand what the problem is.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 1:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, enable the log, and find out why Hibernate tries to insert a null value into a not null column. It will be something trivial; perhaps as simple as a bad unsaved-value mapping.


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.