Posted By:
Kiran_Kumar
Posted On:
Friday, May 12, 2006 03:47 AM
Right now Im using Threads in my Programme.At a time i made minimum 6 threads to run.Each thread will do some operation finally it should fetch the collected data into DataBase. The Table has a primary key which is of type aut increment. So at a time 2 thread's can't fetch the data into Data Base.So i have used Synchronized Block in my code,where exactly the code related to fetching into DataBase.I have overcome that problem upto some extent.But after some time its throwing some exception as below......... -------------------------------------------------------------- org.hibernate.exception.ConstraintViolationException: could not insert: [Advance d.Blogs.SubUrlMaster] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorC
More>>
Right now Im using Threads in my Programme.At a time i made minimum 6 threads to run.Each thread will do some operation finally it should fetch the collected data into DataBase.
The Table has a primary key which is of type aut increment. So at a time 2 thread's can't fetch the data into Data Base.So i have used Synchronized Block in my code,where exactly the code related to fetching into DataBase.I have overcome that problem upto some extent.But after some time its throwing some exception as below.........
-------------------------------------------------------------- org.hibernate.exception.ConstraintViolationException: could not insert: [Advance d.Blogs.SubUrlMaster] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter .java:74) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp er.java:43) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit yPersister.java:1839) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit yPersister.java:2171) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.ja va:46) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutio ns(AbstractFlushingEventListener.java:274) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlus hEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669) at Advanced.Blogs.CrawlSubUrls.FetchToDb(CrawlSubUrls.java:224) at Advanced.Blogs.CrawlSubUrls.putSubUrl(CrawlSubUrls.java:171) at Advanced.Blogs.CrawlSubUrls.process_CCount0(CrawlSubUrls.java:140) at Advanced.Blogs.CrawlSubUrls.CrawlLevelTest(CrawlSubUrls.java:85) at Advanced.Blogs.CrawlSubUrls.run(CrawlSubUrls.java:66) Caused by: java.sql.SQLException: Duplicate entry '6585' for key 1 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531) at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedSt atement.java:1366) at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPrepared Statement.java:952) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java :1974) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java :1897) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java :1758) at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.j ava:22) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit yPersister.java:1823) ... 13 more ----------------------------------------------------------------
So Can u plz suggest me the best approach...... And here is the code .......
synchronized(this){
Transaction tx = null;
tx = session1.beginTransaction();
SubUrlMaster surm = new SubUrlMaster();
surm.setUrlId(urlid_db); surm.setSubUrl(str_CURL);
surm.setStatus(0); surm.setCrawledOntology("0");
surm.setCrawlDepth(crawlLevel_db);
surm.setCrawlTimeStamp(t_stamp);
synchronized(this){
session1.saveOrUpdate(surm);
tx.commit(); }
System.out.println("SUB URL MASTER UPDATED");
session1.flush() ;
}
Thanks & Regards
Kiran Kumar.K
<<Less