-->
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.  [ 3 posts ] 
Author Message
 Post subject: Inconsistency with insert results
PostPosted: Wed Oct 20, 2004 1:12 am 
Newbie

Joined: Tue Oct 12, 2004 6:28 am
Posts: 6
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.2

The generated SQL (show_sql=true):None

Debug level Hibernate log excerpt:None

Log 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


Top
 Profile  
 
 Post subject: HypersonicSQL Inconsistency
PostPosted: Fri Oct 22, 2004 5:21 am 
Newbie

Joined: Tue Oct 12, 2004 6:28 am
Posts: 6
Code:
public class HibernateUtility {

   private static SessionFactory factory;
   
   public static Session getSession(File file) throws HibernateException{
      if(factory==null){
         factory= new Configuration().configure(file).buildSessionFactory();
      }
      Session sess =factory.openSession();
      sess.setFlushMode(FlushMode.COMMIT);
      return sess;
   }
   
   public static void closeSession(Session s){
      try{
         s.close();
      }
      catch(HibernateException he){
         he.printStackTrace();
      }      
   }
   
   public static boolean saveObject(Session s, Object o) throws Exception{
      boolean bSaved = false;
      Transaction tx = null;
      try{
         tx = s.beginTransaction();
         s.saveOrUpdate(o);
         bSaved = true;
         tx.commit();
         
      }finally{
         return bSaved;
      }
   }
   
   public static boolean deleteObject(Session s, Object o) throws Exception{
      boolean bDeleted = false;
      Transaction tx = null;
      try{
         tx = s.beginTransaction();
         s.delete(o);
         bDeleted= true;
         tx.commit();      
      }finally{
         return bDeleted;
      }
   }

}


Job.hbm.xml
Code:
<hibernate-mapping>
   <!-- Job root -->
   <class name="org.etisalat.agent.model.Job" table="Job">
      <id name="id" type="long" column="id" unsaved-value="null">
         <generator class="increment"/>
      </id>
      <property name="name" column="name" type="string"/>
      <property name="interval" column="period_value" type="integer"/>
      <property name="periodType" column="period_type" type="integer"/>
      <property name="startSchedule" column="start_date" type="timestamp"/>
      <property name="nextSchedule" column="next_time" type="timestamp"/>
      <property name="state" column="activity" type="integer"/>
      <set name="processes" table="JobTasks" lazy="true">
         <key column="id"/>
         <one-to-many class="org.etisalat.agent.model.JobProcess"/>
      </set>
   </class>
</hibernate-mapping>

JobProcess.hbm.xml
Code:
<hibernate-mapping>

   <!-- Job Process root -->
   <class name="org.etisalat.agent.model.JobProcess" table="JobTasks">
      <id name="id" type="long" column="id" unsaved-value="null">
         <generator class="increment"/>
      </id>
      <many-to-one name="tool" column="tool_id" class="org.etisalat.agent.model.Tool"/>
      <many-to-one name="job" column="job_id" class="org.etisalat.agent.model.Job"/>
      <property name="name" column="name" type="string"/>
      <property name="order" column="order_no" type="integer"/>
      <property name="status" column="status" type="integer"/>
      <property name="processTime" column="process_time" type="integer"/>
      <property name="toolConfig" column="tool_conf" type="string"/>
      
   </class>
</hibernate-mapping>


Ive included the HibernateUtility in my code. Ive also attached the hbm.xml files for my application. The log from the database says it all but I cant figure out how to commit the rest of the JobProcesses (the first one is saved).

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 3:18 am 
Newbie

Joined: Tue Oct 12, 2004 6:28 am
Posts: 6
As it turns out the problem was with the hbm.xml file. There was an added relationship with the job and job process with their respective ids. The result was that the jobprocess will only be available if there is a job with the same id.

Solved the problem by changing the job.hbm.xml file.
Code:
<set name="processes" table="JobTasks" lazy="true">
         <key column="job_id"/>
         .............
</set>
 


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