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-insertsI 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]