eClPiselink如何管理桌锁?
我需要一些侵犯或帮助您可视化我遇到的问题。问题是,我在应用程序Java 6,数据库MySQL,Ecpliselink 1.0.1,Glassfish 2.1中工作。
有时,某些功能有问题可以访问数据库,并且看到我发现的日志:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
Error Code: 1205
Call: UPDATE table_person SET sip_codigo_barra_bat_64 = ?, sip_version = ? WHERE ((sip_id = ?) AND (sip_version = ?))
bind => [null, 2, 89608, 1]
搜索另一个stackoverflow帖子,我喜欢它可能是一个死锁,在我的代码中,有一种方法可能是问题,但是我对Elcpiselink如何管理锁有一些疑问。
1-如果我的Java方法没有任何锁定注释,请反正锁定桌子?还是取决于游泳池的连接?还是什么?
2-如果三个线程同时执行相同的Java方法,并且该方法对同一表A进行了执行,则可以执行一个更新,然后执行另一个可以生成死锁的更新?如何?
3-我认为我遇到的问题是这样做类似的方法中的僵局,它可以修改两个表:table_person和table_payment(table_payment具有toble_person的前键)
public void method(Integer id){
//Select table_person element from database
Query q = em.createNativeQuery("SELECT * from table_persona where id=id", Pèrson.class);
tablePersonElement=q.getResultList().get(0);
//Select table_payment from database
Query q = em.createNativeQuery("SELECT * from table_payment where id_table_persona=id", Payment.class);
tablePaymentElement=q.getResultList().get(0);
//If tablePaymentElement element doesnt exists is created
if(tablePaymentElement==null){
tablePaymentElement=new Payment();
tablePaymentElement.setMoney(money);
tablePaymentElement.setIdTablePerson(tablePersonElement);
em.persist(tablePaymentElement);
em.flush();
}else{
tablePaymentElement=new Payment();
tablePaymentElement.setMoney(money);
tablePaymentElement.setIdTablePerson(tablePersonElement);
em.merge(tablePaymentElement);
em.flush();
}
//Finally it set some values of tablePerson and save it
tablePersonElement.setValue(value);
em.merge(tablePersonElement);
em.flush();
}
可以用这种方法生成死锁吗?还是如果其他方法在执行时更新table_person的内容?
I need some aproach or help to visualize a problem im having. The thing is, I work in an application Java 6, database mysql, ecpliselink 1.0.1, glassfish 2.1.
Sometimes some of the functionalities have problems to access the database, and seeing the log I found this:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
Error Code: 1205
Call: UPDATE table_person SET sip_codigo_barra_bat_64 = ?, sip_version = ? WHERE ((sip_id = ?) AND (sip_version = ?))
bind => [null, 2, 89608, 1]
Searching another Stackoverflow post I fond out that it could be a dead-lock, and in my code there is a method that could be the problem, but I have some doubts of how elcpiselink manage the locks.
1-If my Java method doesnt have any lock annotation, Eclipselink lock the table anyways? or depends of the poolconnection? or what?
2-If three threads execute the same Java method at the same time and the method execute for the same table a SELECT, then an UPDATE, and then another UPDATE that could generate a dead-lock? how?
3-I think that the problem I have is a deadlock in a method that does something like this, it modify two tables: table_person and table_payment (table_payment has a foreing key to table_person)
public void method(Integer id){
//Select table_person element from database
Query q = em.createNativeQuery("SELECT * from table_persona where id=id", Pèrson.class);
tablePersonElement=q.getResultList().get(0);
//Select table_payment from database
Query q = em.createNativeQuery("SELECT * from table_payment where id_table_persona=id", Payment.class);
tablePaymentElement=q.getResultList().get(0);
//If tablePaymentElement element doesnt exists is created
if(tablePaymentElement==null){
tablePaymentElement=new Payment();
tablePaymentElement.setMoney(money);
tablePaymentElement.setIdTablePerson(tablePersonElement);
em.persist(tablePaymentElement);
em.flush();
}else{
tablePaymentElement=new Payment();
tablePaymentElement.setMoney(money);
tablePaymentElement.setIdTablePerson(tablePersonElement);
em.merge(tablePaymentElement);
em.flush();
}
//Finally it set some values of tablePerson and save it
tablePersonElement.setValue(value);
em.merge(tablePersonElement);
em.flush();
}
Is possible to generate a deadlock with this method? or in case that other method update something of table_person while this one is executing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论