You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by "David Allen (JIRA)" <ji...@apache.org> on 2011/03/11 12:56:59 UTC
[jira] Created: (OPENEJB-1443) EntityManager in non-transactional
business methods using queries can be used only once
EntityManager in non-transactional business methods using queries can be used only once
---------------------------------------------------------------------------------------
Key: OPENEJB-1443
URL: https://issues.apache.org/jira/browse/OPENEJB-1443
Project: OpenEJB
Issue Type: Bug
Components: integration
Affects Versions: 3.1.4
Reporter: David Allen
A call without any transaction on a business method which does not require a transaction cannot use the EntityManager after making a query. The Query object is wrapped by JtaQuery which closes the EntityManager after any call to the object. The following is an example that does not work when called outside of any transaction, where em is the injected EntityManager:
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public City getCity(String cityName) {
Query query = null;
query = em.createNamedQuery("City.RetrieveCityByName");
query.setParameter(1, cityName);
if (!query.getResultList().isEmpty())
--> return (City) query.getResultList().get(0);
else
throw new RuntimeException("Cannot locate a city named " +
cityName);
}
The first call to getResultList() is OK, but the second call fails because it already closed the EntityManager. The following stack trace excerpt shows the stack in OpenEJB during the second call to getResultList():
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1516)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.close(EntityManagerImpl.java:1380)
at org.apache.openejb.persistence.JtaQuery.getResultList(JtaQuery.java:45)
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (OPENEJB-1443) EntityManager in
non-transactional business methods using queries can be used only once
Posted by "David Blevins (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENEJB-1443?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13191085#comment-13191085 ]
David Blevins commented on OPENEJB-1443:
----------------------------------------
2011-11-29 - http://svn.apache.org/viewvc?view=revision&revision=1207802 - rmannibucau
> EntityManager in non-transactional business methods using queries can be used only once
> ---------------------------------------------------------------------------------------
>
> Key: OPENEJB-1443
> URL: https://issues.apache.org/jira/browse/OPENEJB-1443
> Project: OpenEJB
> Issue Type: Bug
> Components: integration
> Affects Versions: 3.1.4
> Reporter: David Allen
> Fix For: 4.0.0-beta-2
>
>
> A call without any transaction on a business method which does not require a transaction cannot use the EntityManager after making a query. The Query object is wrapped by JtaQuery which closes the EntityManager after any call to the object. The following is an example that does not work when called outside of any transaction, where em is the injected EntityManager:
> @TransactionAttribute(TransactionAttributeType.SUPPORTS)
> public City getCity(String cityName) {
> Query query = null;
> query = em.createNamedQuery("City.RetrieveCityByName");
> query.setParameter(1, cityName);
> if (!query.getResultList().isEmpty())
> --> return (City) query.getResultList().get(0);
> else
> throw new RuntimeException("Cannot locate a city named " +
> cityName);
> }
> The first call to getResultList() is OK, but the second call fails because it already closed the EntityManager. The following stack trace excerpt shows the stack in OpenEJB during the second call to getResultList():
> Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
> at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1516)
> at org.eclipse.persistence.internal.jpa.EntityManagerImpl.close(EntityManagerImpl.java:1380)
> at org.apache.openejb.persistence.JtaQuery.getResultList(JtaQuery.java:45)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Closed] (OPENEJB-1443) EntityManager in non-transactional
business methods using queries can be used only once
Posted by "Romain Manni-Bucau (Closed) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENEJB-1443?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Romain Manni-Bucau closed OPENEJB-1443.
---------------------------------------
Resolution: Fixed
Fix Version/s: 4.0-beta-2
should be ok on trunk
> EntityManager in non-transactional business methods using queries can be used only once
> ---------------------------------------------------------------------------------------
>
> Key: OPENEJB-1443
> URL: https://issues.apache.org/jira/browse/OPENEJB-1443
> Project: OpenEJB
> Issue Type: Bug
> Components: integration
> Affects Versions: 3.1.4
> Reporter: David Allen
> Fix For: 4.0-beta-2
>
>
> A call without any transaction on a business method which does not require a transaction cannot use the EntityManager after making a query. The Query object is wrapped by JtaQuery which closes the EntityManager after any call to the object. The following is an example that does not work when called outside of any transaction, where em is the injected EntityManager:
> @TransactionAttribute(TransactionAttributeType.SUPPORTS)
> public City getCity(String cityName) {
> Query query = null;
> query = em.createNamedQuery("City.RetrieveCityByName");
> query.setParameter(1, cityName);
> if (!query.getResultList().isEmpty())
> --> return (City) query.getResultList().get(0);
> else
> throw new RuntimeException("Cannot locate a city named " +
> cityName);
> }
> The first call to getResultList() is OK, but the second call fails because it already closed the EntityManager. The following stack trace excerpt shows the stack in OpenEJB during the second call to getResultList():
> Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
> at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1516)
> at org.eclipse.persistence.internal.jpa.EntityManagerImpl.close(EntityManagerImpl.java:1380)
> at org.apache.openejb.persistence.JtaQuery.getResultList(JtaQuery.java:45)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira