Hibernate version:2.1.6
Mapping documents:None
Code between sessionFactory.openSession() and session.close():
Code:
public void testInitJobTasks(){
int times = 3;
try{
java.util.Random random = new java.util.Random();
Job job= new JobList().getJob(new Long(1));
Tool tool= new JobList().getTool("ping");
Session s =HibernateUtility.getSession(new File(OperationHandler.GLOBAL_DATABASE_FILE));
for(int i=1;i<=times;i++){
JobProcess mJobProcess = new JobProcess();
mJobProcess.setProcessID(random.nextLong());
mJobProcess.setOrder(i);
mJobProcess.setProcessTime(i);
mJobProcess.setStatus(0);
mJobProcess.setToolConfig("-k123");
mJobProcess.setJob(job);//Foreign Key
mJobProcess.setTool(tool);//Foreign Key
HibernateUtility.saveObject(s,mJobProcess);
}
s.close();
}
catch(Exception e){
e.printStackTrace();
}
finally{
int size= new JobList().getJobList().size();
System.err.println("Collected "+size+" JobProcesses!!");
}
}
Full stack trace of any exception that occurs:Name and version of the database you are using:hsqldb1.7.2The generated SQL (show_sql=true):NoneDebug level Hibernate log excerpt:NoneLog output from HSQLDB Database:Code:
[Server@d9dc39]: [Thread[HSQLDB Server @d9dc39,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=4256,localport=9001]) entered
[Server@d9dc39]: [Thread[HSQLDB Server @d9dc39,5,main]]: handleConnection() exited
[Server@d9dc39]: [Thread[HSQLDB Connection @99681b,5,HSQLDB Connections @d9dc39]]: 36:trying to connect user SA
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:HSQLCLI:SETSESSIONATTR:AUTOCOMMIT false CONNECTION_READONLY null
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:SQLCLI:SQLPREPARE select this.id as id0_, this.name as name0_, this.description as descript3_0_, this.path as path0_ from Tool this where this.name=?
[Server@d9dc39]: 36:SQLCLI:SQLEXECUTE:120
[Server@d9dc39]: 36:SQLCLI:SQLFREESTMT:120
[Server@d9dc39]: 36:SQLCLI:SQLENDTRAN:COMMIT
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:SQLCLI:SQLPREPARE select max(id) from JobTasks
[Server@d9dc39]: 36:SQLCLI:SQLEXECUTE:121
[Server@d9dc39]: 36:SQLCLI:SQLFREESTMT:121
[Server@d9dc39]: 36:SQLCLI:SQLPREPARE insert into JobTasks (tool_id, job_id, order_no, status, process_time, tool_conf, id) values (?, ?, ?, ?, ?, ?, ?)
[Server@d9dc39]: 36:SQLCLI:SQLEXECUTE:122
[Server@d9dc39]: 36:SQLCLI:SQLFREESTMT:122
[Server@d9dc39]: 36:SQLCLI:SQLENDTRAN:COMMIT
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:SQLCLI:SQLPREPARE insert into JobTasks (tool_id, job_id, order_no, status, process_time, tool_conf, id) values (?, ?, ?, ?, ?, ?, ?)
[Server@d9dc39]: 36:SQLCLI:SQLEXECUTE:123
[Server@d9dc39]: 36:SQLCLI:SQLFREESTMT:123
[Server@d9dc39]: 36:SQLCLI:SQLENDTRAN:COMMIT
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:SQLCLI:SQLPREPARE insert into JobTasks (tool_id, job_id, order_no, status, process_time, tool_conf, id) values (?, ?, ?, ?, ?, ?, ?)
[Server@d9dc39]: 36:SQLCLI:SQLEXECUTE:124
[Server@d9dc39]: 36:SQLCLI:SQLFREESTMT:124
[Server@d9dc39]: 36:SQLCLI:SQLENDTRAN:COMMIT
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:HSQLCLI:GETSESSIONATTR
[Server@d9dc39]: 36:SQLCLI:SQLPREPARE select this.id as id0_, this.name as name0_, this.period_value as period_v3_0_, this.period_type as period_t4_0_, this.start_date as start_date0_, this.next_time
as next_time0_, this.activity as activity0_ from Job this where 1=1
[Server@d9dc39]: 36:SQLCLI:SQLEXECUTE:125
[Server@d9dc39]: 36:SQLCLI:SQLFREESTMT:125
[Server@d9dc39]: 33:SQLCLI:SQLDISCONNECT
[Server@d9dc39]: [Thread[HSQLDB Connection @482923,5,HSQLDB Connections @d9dc39]]: 33:disconnected SA
[Server@d9dc39]: 35:SQLCLI:SQLDISCONNECT
[Server@d9dc39]: 36:SQLCLI:SQLENDTRAN:COMMIT
[Server@d9dc39]: [Thread[HSQLDB Connection @b383e9,5,HSQLDB Connections @d9dc39]]: 35:disconnected SA
[Server@d9dc39]: [Thread[HSQLDB Connection @99681b,5,HSQLDB Connections @d9dc39]]: 36:disconnected SA
I noticed that when inserting some job process objects that only the first one is added and the other two are left behind. I think it has something to do do with the commit statement. Im using a utility that using an existing session object and builds,saves and commits using the hibernate transaction object. This works well with my other code but in this case Im stuck.
1) Is there a way to remedy this using some sort of automatic autocommit or other solution.
2) Has this problem been noted with HSQLDB? MySQL shows no inconsistency for the above test.
Thanks