-->
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: I am having Issues with commiting the transaction
PostPosted: Fri Dec 16, 2005 11:08 pm 
Newbie

Joined: Fri Dec 16, 2005 10:35 pm
Posts: 2
Hi,

I m doing like this. Please let me know where i am going wrong.

I am trying to insert one row under Hibernate Transaction.

Step 1:
i have inserted one row using session.save(myObj) and it saved in a database.

Step 2:
i have deleted row manually in my database.(My application sometime requires manual deletion if application is down for sometime. So i m testing that.)

Step 3 :
when i tried to insert the row using my program, i m getting the insert log stating its being inserted but the row is not inserted in the database and i didnt get any exception.(Transaction is ok i checked FAQ and it said it may be the problem ). I have done

session.flush()
session.clear()
session.close() also in the required places.

When i again run my program, i m getting UNIQUE CONSTRAINT Violated or could not start a new transaction exceptions.

Only if i restart my server then i can able to do my database operations.

Could you please tell me how can i clear cache/session so that i can use Hibernate effectively or am i doing anything wrong in my Transaction settings ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 11:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You need to show your code as its incomplete and we can only guess at what might be going on.

In anycase, you will need to make sure you do use transactions in these oeprations. I am not sure you are as you did not show a start transaction or a commit etc. To answer one of your questions; session.clear() clears the session cache.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 11:36 pm 
Newbie

Joined: Fri Dec 16, 2005 10:35 pm
Posts: 2
Below is my test program....

Here first i am querying the table with ID 100 . If it exists dont insert otherwise it will insert new row.

public class HibernateTest {

public static void main(String[] args)throws Exception {

try {

Configuration cfg = new Configuration();
cfg.configure("/hibernateTest.cfg.xml");

SessionFactory sessionFactory = cfg.buildSessionFactory();

Session session = sessionFactory.openSession();

Query query = session.getNamedQuery("queryID");

Transaction tran=session.beginTransaction();

List result = query.list();

System.out.println("****2....................result = " + result);

DataSet ds = (DataSet)result.get(0);
session.flush();

EsbServiceFieldPermission[] serviceFieldPermission=new
EsbServiceFieldPermission[2];
query.setInteger(0,100);
EsbServiceTransformation esbServiceTransformation=(EsbServiceTransformation)query.uniqueResult();


//If ID exists do nothing else insert in field permissions
if(esbServiceTransformation==null){
EsbServiceTransformation esb1=new EsbServiceTransformation();
esb1.setTransformationId("100");
esb1.setXsltStylesheet("none");
esb1.setTransformationType("bye");
esb1.setTransMessageSet("bye");
esb1.setTransMessageType("bye");
session.save(esb1);

EsbServiceFieldPermission[] serviceFieldPermissioN=new EsbServiceFieldPermission[2];
serviceFieldPermissioN[0]=new EsbServiceFieldPermission();
serviceFieldPermissioN[0].setFieldXpath("/a/b/c");
serviceFieldPermissioN[0].setTransformationId("100");
session.save(serviceFieldPermissioN[i]);
tran.commit();
}else {
System.out.println("id already there");
}

}finally{
session.flush();
session.clear();
session.close();
}
}




queryID is like this defined in configuration

select queryID from tablename where id=?

Could u please let me know whats wrong in this ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 11:05 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 7:07 pm
Posts: 21
Try this: After INSERT, bring down ur appserver really and then delete that row from db. Then after starting ur app server do the rest. There may be probs in synchronisation if u delete a row manualy with appserver ON.
This does not violate the cause of the test as well - infact this is closer to reality


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.