私はEJBにこのコードを持っています:
try{
em.persist(joueur);
em.persist(p);
em.persist(astre);
em.persist(planet);
em.flush();
}catch(Exception e){
logger.log(Level.FATAL, "test");
// ExceptionManager.manageExceptions(e);
}
このコードは、(PostGreQSL を介して) トリガーを作成していくつかの制約をチェックし、テスト値を使用してトリガーを起動したため、例外をスローする必要があります。
私のログが表示さtest
れ、catch ブロックに入りますが、サーバー ログにすべての例外スタックが表示され、理由がわからないため、私のコードは「すべて」または「完全な」例外をキャッチしません。このコードのように、後に例外がスローされます...
メソッドを呼び出してflush()
エンティティをデータベースにすぐに保存する必要があることはわかっていますが、ここでは機能せず、例外がまだコードに伝播されているようです。
数週間前、このコードは機能しましたが、私は別のプロジェクト ファセットに取り組んでおり、現在、何らかの回帰があるようで、その理由がわかりません...
だから私の質問はこれです:EntityManager.flush()
常に永続化アクションをすぐに実行しますか?
編集: ここに私のログがあります (少し省略) (最初 -> GF ログ、2番目 -> Log4j 個人ログ): 申し訳ありませんがフランス語版ですが、例外名は同じままです;)
[#|2013-01-10T15:03:28.218+0100|WARNING|glassfish3.1.2|org.eclipse.persistence.session.file:/E:/softs/serveurs/glassfish3_1122/glassfish/domains/domain1/applications/ear-0.0.1-SNAPSHOT/lib/entities-0.0.1-SNAPSHOT.jar_01|_ThreadID=72;_ThreadName=Thread-2;|Local
Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERREUR: le pseudo est déjà pris (player_name)=(hghghghggg)
Error Code: 0
Call: INSERT INTO pretoria.pseudos (ID, CHANGEMENT, PSEUDO, VERSION, joueur_id) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
Query: InsertObjectQuery(com.sim.entities.Pseudo@190c460)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1494)
................
Caused by: org.postgresql.util.PSQLException: ERREUR: le pseudo est déjà pris (player_name)=(hghghghggg)
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
................
|#]
[#|2013-01-10T15:03:28.218+0100|WARNING|glassfish3.1.2|org.eclipse.persistence.session.file:/E:/softs/serveurs/glassfish3_1122/glassfish/domains/domain1/applications/ear-0.0.1-SNAPSHOT/lib/entities-0.0.1-SNAPSHOT.jar_01|_ThreadID=72;_ThreadName=Thread-2;|Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERREUR: la transaction est annulée, les commandes sont ignorées jusqu'à la fin du bloc
de la transaction
Error Code: 0
Call: INSERT INTO pretoria.joueurs (ID, BLOQUE, cle_validation, creation, EMAIL, LANGAGE, maj_temperament, NEWSLETTER, PASSWORD, POUSSIERE, SEL, TEMPERAMENT, VACANCES, VERSION, alliance_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [15 parameters bound]
Query: InsertObjectQuery(com.sim.entities.Joueur@1a21ad9)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1494)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:838)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:906)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:592)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1717)
................
Caused by: org.postgresql.util.PSQLException: ERREUR: la transaction est annulée, les commandes sont ignorées jusqu'à la fin du bloc
de la transaction
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
................
|#]
[#|2013-01-10T15:03:28.234+0100|WARNING|glassfish3.1.2|org.eclipse.persistence.session.file:/E:/softs/serveurs/glassfish3_1122/glassfish/domains/domain1/applications/ear-0.0.1-SNAPSHOT/lib/entities-0.0.1-SNAPSHOT.jar_01.transaction|_ThreadID=72;_ThreadName=Thread-2;|Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERREUR: la transaction est annulée, les commandes sont ignorées jusqu'à la fin du bloc
de la transaction
Error Code: 0
Call: INSERT INTO pretoria.joueurs (ID, BLOQUE, cle_validation, creation, EMAIL, LANGAGE, maj_temperament, NEWSLETTER, PASSWORD, POUSSIERE, SEL, TEMPERAMENT, VACANCES, VERSION, alliance_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [15 parameters bound]
Query: InsertObjectQuery(com.sim.entities.Joueur@1a21ad9)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1494)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:838)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:906)
................
Caused by: org.postgresql.util.PSQLException: ERREUR: la transaction est annulée, les commandes sont ignorées jusqu'à la fin du bloc
de la transaction
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
................
|#]
[#|2013-01-10T15:03:28.234+0100|WARNING|glassfish3.1.2|javax.enterprise.system.core.transaction.com.sun.jts.jta|_ThreadID=72;_ThreadName=Thread-2;|JTS5054: Unexpected error occurred in after completion
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERREUR: la transaction est annulée, les commandes sont ignorées jusqu'à la fin du bloc
de la transaction
Error Code: 0
Call: INSERT INTO pretoria.joueurs (ID, BLOQUE, cle_validation, creation, EMAIL, LANGAGE, maj_temperament, NEWSLETTER, PASSWORD, POUSSIERE, SEL, TEMPERAMENT, VACANCES, VERSION, alliance_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [15 parameters bound]
Query: InsertObjectQuery(com.sim.entities.Joueur@1a21ad9)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1494)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:838)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:906)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:592)
................
Caused by: org.postgresql.util.PSQLException: ERREUR: la transaction est annulée, les commandes sont ignorées jusqu'à la fin du bloc
de la transaction
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
................
|#]
[#|2013-01-10T15:03:28.234+0100|WARNING|glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=72;_ThreadName=Thread-2;|EJB5184:A system exception occurred during an invocation on EJB AccountBean, method: public void com.sim.ejbs.stateless.AccountBean.createAccount(java.lang.String,char[],java.lang.String,com.sim.basics.enums.TemperamentEnum,com.sim.dtos.xml.universes.Universe,int,int,int,java.lang.String,java.lang.String) throws com.sim.basics.exceptions.SimRuntimeException|#]
[#|2013-01-10T15:03:28.234+0100|WARNING|glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=72;_ThreadName=Thread-2;|javax.ejb.EJBException: Transaction aborted
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5142)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:89)
................
Caused by: javax.transaction.RollbackException
at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:334)
at com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.commitDistributedTransaction(JavaEETransactionManagerJTSDelegate.java:185)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:861)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5136)
... 53 more
|#]
Log4j ログ:
2013-01-10 15:03:28,218 FATAL [com.sim.ejbs.stateless.AccountBean]
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERREUR: le pseudo est déjà pris (player_name)=(hghghghggg)
Error Code: 0
Call: INSERT INTO pretoria.pseudos (ID, CHANGEMENT, PSEUDO, VERSION, joueur_id) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
Query: InsertObjectQuery(com.sim.entities.Pseudo@190c460)
2013-01-10 15:03:28,234 FATAL [com.sim.web.beans.LoginBean] 123