-->
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.  [ 2 posts ] 
Author Message
 Post subject: At most 30 updates?!
PostPosted: Tue Jan 31, 2006 7:27 am 
Newbie

Joined: Fri Dec 23, 2005 7:54 am
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1

I thought I was almost done with this prototype but then I build this test:

Code:
    public void testMultipleInsertions() throws Exception {
        List<Measure> mm = MeasureLoaderTest.loadFromURL(u, maxSize);

        try {
            dao.save(mm);
            getSession().getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }


        getSession().beginTransaction();

        List<Measure> ret = getSession().createQuery("from Measure m").list();
        assertEquals(mm.size(), ret.size());
       
        getSession().getTransaction().commit();

    }



The maxSize field limits how many Measures get loaded.
This test pass for maxSize<31 and will fail with greater values.

In dao.save() I have

Code:
    public void save(List<Measure> measures) {
        int i = 0;
        for (Measure measure : measures) {
            session.save(measure);
            if (i % 30 == 0) {
                session.flush();
                session.clear();
            }
            i++;
        }
    }


As suggested in http://www.hibernate.org/hib_docs/v3/reference/en/html/batch.html#batch-inserts

I have been playing with this modulus; now it's 30 becouse this is the threshold value of my test.
I also have added the entry:

Code:
...
setProperty("hibernate.jdbc.batch_size", "50").
...

when setting the SessionFactory, but nothing changes.

Any clue?
Beside this, how do I check out if the the system property "hibernate.jdbc.batch_size" has been correctly set up? doing
System.getProperty("hibernate.jdbc.batch_size") returns null...

I'm stuck, I have to say...



Full stack trace of any exception that occurs:
Code:
Hibernate: update MEASURES set QUERY_TYPE_CODE=?, SERVER_NAME=?, TEST_BOX_NAME=?, tm=?, attempt=?, answer=?, delay=? where MEASURE_ID=?
12:15:41,947  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: null
12:15:41,949 ERROR JDBCExceptionReporter:72 - failed batch
12:15:41,954 ERROR AbstractFlushingEventListener:299 - 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:91)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
   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:230)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at net.ripe.dnsmon.measures.MeasureDAOTest.testMultipleInsertions(MeasureDAOTest.java:112)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   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.textui.TestRunner.doRun(TestRunner.java:116)
   at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:57)
   at junit.textui.TestRunner.start(TestRunner.java:172)
   at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
   at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:97)
   at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
Caused by: java.sql.BatchUpdateException: failed batch
   at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
   ... 31 more




Name and version of the database you are using:
HSQL 1.8
[/url]


Top
 Profile  
 
 Post subject: solved
PostPosted: Tue Jan 31, 2006 6:33 pm 
Newbie

Joined: Fri Dec 23, 2005 7:54 am
Posts: 12
The problem happened when trying to save the 31st object, which didn't have a related object persisted...

I still wonder wy I don't get an FK violation instead of this (almost, for me at least) meaningless exception.


Francesco


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