I am currently developing a Java EE application. Therefore I am using glassfish 4.1.1 and EclipseLink as OR-Mapper. As transaction type I use JTA. My problem is, when creating teams in a for-loop it failes randomly at some point.
public class MyBean {
@PersistenceContext
private EntityManager em;
public Team createTeam(String name) throws TeamnameAlreadyUsedException {
Team team = null;
try{
team= em.createNamedQuery("Team.findByName", Team.class).setParameter("teamname", name).getSingleResult();
}
catch (NoResultException e){
}
if(team == null) {
team = new Team();
team.setTeamname(teamname);
em.persist(team);
return team;
}
throw new TeamnameAlreadyUsedException();
}
some method in my servlet beeing triggered by a doGet URL-pattern:
private void someMethod() {
for(int i=0; i<10; i++) {
try {
Team team = teamBean.createTeam("Team" + i);
} catch (TeamnameAlreadyUsedException e) {
e.printStackTrace();
} catch (EJBException e) {
e.printStackTrace();
}
}
}
Now calling this method works just fine. The teams are beeing created in the database and TeamnameAlreadyUsedException is thrown when they are already created. The problem is, when calling this method about 10-30 times, at some point I get an EJBException and need to completely restart glassfish for the website to work again.
Communication failure detected when attempting to perform read query outside of
a transaction. Attempting to retry query. Error was: Exception [EclipseLink-
4002] (Eclipse Persistence Services - 2.6.2.qualifier):
org.eclipse.persistence.exceptions.DatabaseException
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.2.qualifier): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
Error Code: 0
Aucun commentaire:
Enregistrer un commentaire