8 Replies Latest reply on Aug 12, 2013 4:13 PM by Em Ka

    Dynamically create entityManager and transactions problems

    Em Ka Newbie

      I created entity manager like this(I have to create it dynamically):


          private EntityManagerFactory getEntityManagerFactoryForCompany(CoreCompany company) {
              Properties properties = getProperties(company.getDatabaseConnection());
              return Persistence.createEntityManagerFactory(PERSISTANCE_UNIT, properties);
          }
      
          private Properties getProperties(CoreCompanyDatabaseConnection databaseConnection) {
              Properties properties = new Properties();
              properties.put("javax.persistence.jtaDataSource" , "java:/company_12_dataSource");
              properties.put("javax.persistence.transactionType", "RESOURCE_LOCAL");
              properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
              properties.put("hibernate.show_sql", "true");
              properties.put("hibernate.format_sql", "true");
      //        properties.put("hibernate.transaction.jta.platform","org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform");
              return properties;
          }
      

       

       

      When I'm trying select something from database I have errors like

       

      Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000460: Error checking for a transaction
              at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137)
              at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)
              at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:276)
              at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
              ... 46 more
      Caused by: javax.resource.ResourceException: IJ000460: Error checking for a transaction
              at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:362)
              at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464)
              at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)
              ... 49 more
      Caused by: javax.resource.ResourceException: IJ000459: Transaction is not active: tx=TransactionImple < ac, BasicAction: 0:ffff7f000101:-38b973cb:51820aaa:14 status: ActionStatus.ABORT_ONLY >
              at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:352)
              ... 51 more
      

       

      How I should configure properties?

       

      Ah and my code for select query:

       

          private void initializeEntityManager(Long companyId) {
              getEntityManagerForCompany(companyId).createNativeQuery("select now()").getSingleResult();
          }
      
          public EntityManager getEntityManagerForCompany(Long companyId) {
              return entityManagers.get(companyId).createEntityManager();
          }
      
      

       

      When i added entityManager.getTransaction() and then begin and commit I had error: No active transaction.

        • 1. Re: Dynamically create entityManager and transactions problems
          Em Ka Newbie

          And also when i try to merge somthing I have error:

          Caused by: java.lang.IllegalStateException: Transaction not active

                  at org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:101) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

           

              private void mergeWithCustomTransaction(T entity) {

                  try {

                      getEntityManager().getTransaction().begin();

                      getEntityManager().joinTransaction();

                      getEntityManager().merge(entity);

                      getEntityManager().flush();

                      getEntityManager().getTransaction().commit();

                  } catch (Exception e) {

                      e.printStackTrace();

                      getEntityManager().getTransaction().rollback();

                  }

              }

          • 2. Re: Dynamically create entityManager and transactions problems
            Wolf-Dieter Fink Master

            I'm not sure whether I understand your problem, you might post a bit more informations.

             

            From the IJ000459 Exception, could it possible that you have a long running transaction and this is timed out?

            • 3. Re: Dynamically create entityManager and transactions problems
              Em Ka Newbie

              At jboss startup I'm creating map with entityManagerFactory based on data in database. My ejb:

               

               

              @Singleton
              @Startup
              public class CompanyEntityManagerFactory {
              
              
                  @EJB
                  private CoreCompanyFacade companyFacade;
                  private Map<Long, EntityManagerFactory> entityManagers = new HashMap();
                  private final static String PERSISTANCE_UNIT = "PU_SYSTEM";
              
              
                  @PostConstruct
                  public void initializeEntityManagers() {
                      try {
                          Class.forName("org.postgresql.Driver");
                      } catch (ClassNotFoundException ex) {
                          ex.printStackTrace();
                      }
                      for (CoreCompany company : getCompanies()) {
                          entityManagers.put(company.getId(), getEntityManagerFactoryForCompany(company));
                          initializeEntityManager(company.getId());
                      }
                  }
              
              
                  private void initializeEntityManager(Long companyId) {
                      getEntityManagerForCompany(companyId).createNativeQuery("select now()").getSingleResult();
                  }
              
              
                  public EntityManager getEntityManagerForCompany(Long companyId) {
                      return entityManagers.get(companyId).createEntityManager();
                  }
              
              
                  private EntityManagerFactory getEntityManagerFactoryForCompany(CoreCompany company) {
                      Properties properties = getProperties(company.getDatabaseConnection());
                      return Persistence.createEntityManagerFactory(PERSISTANCE_UNIT, properties);
                  }
              
              
                  private Properties getProperties(CoreCompanyDatabaseConnection databaseConnection) {
                      Properties properties = new Properties();
                      properties.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence");
                      //properties.put("hibernate.ejb.entitymanager_factory_name", "PU_" + databaseConnection.getId());
                      properties.put("javax.persistence.transactionType", "RESOURCE_LOCAL");
                      properties.put("javax.persistence.jdbc.user", databaseConnection.getUser());
                      properties.put("javax.persistence.jdbc.password", databaseConnection.getPassword());
                      properties.put("javax.persistence.jdbc.driver", "org.postgresql.Driver");
                      properties.put("javax.persistence.jdbc.url", databaseConnection.getJdbcUrl());
                      properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
                      properties.put("hibernate.show_sql", "true");
                      properties.put("hibernate.format_sql", "true");
                      return properties;
                  }
              
              
                  private List<CoreCompany> getCompanies() {
                      return companyFacade.getCompaniesWithDatabaseConnection();
                  }
              }
              

               

              And this piece of code work correctly only for "SELECT" queries. When I try update entities I have exception:

               

              Caused by: java.lang.IllegalStateException: Transaction not active

                      at org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:101) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

               

              In my previous post is update method: private void mergeWithCustomTransaction(T entity).

               

              I read that when I create entityManagerFactory via Persistence.createEntityManagerFactory() transaction provider is not attached. Or I am making some stupid mistake. ..

               

               

              From the IJ000459 Exception, could it possible that you have a long running transaction and this is timed out?

               

              Nope. It is not long transaction, Now its simple update: update user_groups_ set name_='test'.

              • 4. Re: Dynamically create entityManager and transactions problems
                Scott Marlow Master

                Can you switch to using @PersistenceContext EntityManager or @PersistenceUnit EntityManagerFactory?

                 

                If you insist on doing it the hard way, you could possibly get some ideas of how to configure the persistence unit by looking at the AS JPA container implemention code.  Currently, you can look at the integration module for Hibernate here https://github.com/wildfly/wildfly/blob/master/jpa/hibernate4/src/main/java/org/jboss/as/jpa/hibernate4/HibernatePersistenceProviderAdaptor.java and https://github.com/wildfly/wildfly/blob/master/jpa/hibernate4/src/main/java/org/jboss/as/jpa/hibernate4.

                 

                This example code will show you some additional properties that you can pass in and probably should (The AS JPA EE container automatically adds the additional properties for container managed persistence contexts). 

                 

                Scott

                • 5. Re: Dynamically create entityManager and transactions problems
                  Em Ka Newbie

                  Scott Marlow wrote:

                   

                  Can you switch to using @PersistenceContext EntityManager or @PersistenceUnit EntityManagerFactory?

                   

                  If you insist on doing it the hard way, you could possibly get some ideas of how to configure the persistence unit by looking at the AS JPA container implemention code.  Currently, you can look at the integration module for Hibernate here https://github.com/wildfly/wildfly/blob/master/jpa/hibernate4/src/main/java/org/jboss/as/jpa/hibernate4/HibernatePersistenceProviderAdaptor.java and https://github.com/wildfly/wildfly/blob/master/jpa/hibernate4/src/main/java/org/jboss/as/jpa/hibernate4.

                   

                  This example code will show you some additional properties that you can pass in and probably should (The AS JPA EE container automatically adds the additional properties for container managed persistence contexts). 

                   

                  Scott

                  I can't use @PersistenceContext because I have to use many database. I changed my method getProperties() based on yours info.

                  Now it looks like :

                   

                  @Singleton
                  @Startup
                  public class CompanyEntityManagerFactory {
                  
                  
                      @EJB
                      private CoreCompanyFacade companyFacade;
                      private Map<Long, EntityManagerFactory> entityManagers = new HashMap();
                      private final static String PERSISTANCE_UNIT = "PU_SYSTEM";
                  
                  
                      @PostConstruct
                      public void initializeEntityManagers() {
                          try {
                              Class.forName("org.postgresql.Driver");
                          } catch (ClassNotFoundException ex) {
                              ex.printStackTrace();
                          }
                          for (CoreCompany company : getCompanies()) {
                              entityManagers.put(company.getId(), getEntityManagerFactoryForCompany(company));
                              initializeEntityManager(company.getId());
                          }
                      }
                  
                  
                      private void initializeEntityManager(Long companyId) {
                          getEntityManagerForCompany(companyId).createNativeQuery("select now()").getSingleResult();
                      }
                  
                  
                      public EntityManager getEntityManagerForCompany(Long companyId) {
                          return entityManagers.get(companyId).createEntityManager();
                      }
                  
                  
                      private EntityManagerFactory getEntityManagerFactoryForCompany(CoreCompany company) {
                          Properties properties = getProperties(company.getDatabaseConnection());
                          return Persistence.createEntityManagerFactory(PERSISTANCE_UNIT, properties);
                      }
                  
                  
                      private Properties getProperties(CoreCompanyDatabaseConnection databaseConnection) {
                          Properties properties = new Properties();
                          properties.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence");
                          properties.put("javax.persistence.transactionType", "RESOURCE_LOCAL");
                          properties.put("javax.persistence.jdbc.user", databaseConnection.getUser());
                          properties.put("javax.persistence.jdbc.password", databaseConnection.getPassword());
                          properties.put("javax.persistence.jdbc.driver", "org.postgresql.Driver");
                          properties.put("javax.persistence.jdbc.url", databaseConnection.getJdbcUrl());
                          properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
                          properties.put("hibernate.show_sql", "true");
                          properties.put("hibernate.format_sql", "true");
                          properties.put(Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
                          properties.put(org.hibernate.ejb.AvailableSettings.SCANNER, HibernateAnnotationScanner.class.getName());
                          properties.put(AvailableSettings.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform");
                          properties.remove(AvailableSettings.TRANSACTION_MANAGER_STRATEGY);  // remove legacy way of specifying TX manager (conflicts with JTA_PLATFORM)
                          properties.put(org.hibernate.ejb.AvailableSettings.ENTITY_MANAGER_FACTORY_NAME, PERSISTANCE_UNIT);
                          properties.put(AvailableSettings.SESSION_FACTORY_NAME, PERSISTANCE_UNIT);
                          return properties;
                      }
                  
                  
                      private List<CoreCompany> getCompanies() {
                          return companyFacade.getCompaniesWithDatabaseConnection();
                      }
                  
                  

                   

                  But in HibernatePersistenceProviderAdaptor.java is JBossAppServerJtaPlatform injecting by method void injectJtaManager(JtaManager jtaManager).

                   

                  I think that this could be problem. Question is how I can inject this in my class?

                   

                   

                  Now I chenged update method to:

                   

                      private void mergeWithCustomTransaction(T entity) {
                              getEntityManager().merge(entity);
                              getEntityManager().flush();
                      }
                  

                   

                  And with all changes only select queries are ok. During update I have exception:

                   

                  17:14:56,655 ERROR [stderr] (http--127.0.0.1-8080-1) javax.persistence.TransactionRequiredException: no transaction is in progress

                  17:14:56,657 ERROR [stderr] (http--127.0.0.1-8080-1)    at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:970)

                   

                   

                  Also after few minutes on jboss console I notice :

                   

                  16:59:08,242 WARN  [org.hibernate.internal.SessionFactoryImpl] (MSC service thread 1-1) HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()

                   

                   

                   

                   

                  16:59:17,350 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-1) HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException

                  16:59:17,351 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-1) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory

                  16:59:17,353 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-1) HHH000397: Using ASTQueryTranslatorFactory

                  17:03:53,878 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:54c164c7:51827f06:8 in state  RUN

                  17:03:53,881 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffff7f000101:54c164c7:51827f06:8 invoked while multiple threads active within it.

                  17:03:53,884 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffff7f000101:54c164c7:51827f06:8 aborting with 1 threads active!

                  17:03:53,912 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,main] successfully canceled TX 0:ffff7f000101:54c164c7:51827f06:8

                   

                  I restart jboss and made the same operations and this message didn't show again....

                  • 6. Re: Dynamically create entityManager and transactions problems
                    Scott Marlow Master

                    You could enable TRACE logging for org.hibernate + com.arjuna.  This link might help you get started with enabling logging.

                     

                    Did you EntityManager.joinTransaction()?

                    • 7. Re: Dynamically create entityManager and transactions problems
                      Em Ka Newbie

                      Thanks for all. I changed javax.persistence.transactionType on JTA and add

                              properties.put("transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");

                              properties.put("hibernate.ejb.entitymanager_factory_name", "PU_company_" + databaseConnection.getId());

                       

                      And all stars work correctly!

                      • 8. Re: Dynamically create entityManager and transactions problems
                        Em Ka Newbie

                        I still have problem. Data source crated in this way do not close entity manager. Even if i run entityManager.close() connetcion in postgresql database is still active or idle. I set c3po pooling but this dont work also.

                         

                         

                        So I decided to create data source in jboos via ModelControllerClient. And this is ok. Datasource is ok, I can test it in management console. But how to crate entitymanagerfactory? I could lookup datasource but its WrapperDataSource...

                         

                        My test class:

                         

                         

                        @Singleton
                        @Startup
                        public class TestEntityManager {
                        
                        
                            private final static String PERSISTANCE_UNIT = "PU_SYSTEM";
                        
                        
                            @PostConstruct
                            public void test() {
                                Object ejb = null;
                                final Hashtable jndiProperties = new Hashtable();
                                jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
                                Context ctx;
                                try {
                                    ctx = new InitialContext(jndiProperties);
                                    ejb = ctx.lookup("java:/testowe2");
                        
                        
                                } catch (Exception ex) {
                                    ex.printStackTrace();
                                }
                                //WrapperDataSource dataSource = (WrapperDataSource) ejb;
                        
                        
                                EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTANCE_UNIT, getProperties());
                                EntityManager em = factory.createEntityManager();
                                em.createNativeQuery("select now()").getSingleResult();
                        
                        
                                System.out.println(">>>>>>>");
                            }
                        
                        
                            private Properties getProperties() {
                                Properties properties = new Properties();
                                properties.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence");
                                properties.put("javax.persistence.transactionType", "JTA");
                                properties.put("javax.persistence.jdbc.driver", "org.postgresql.Driver");
                                properties.put(org.hibernate.ejb.AvailableSettings.SCANNER, HibernateAnnotationScanner.class.getName());
                                properties.put(AvailableSettings.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform");
                                properties.put(org.hibernate.ejb.AvailableSettings.ENTITY_MANAGER_FACTORY_NAME, PERSISTANCE_UNIT);
                                properties.put(AvailableSettings.SESSION_FACTORY_NAME, PERSISTANCE_UNIT);
                                properties.put("transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
                                properties.put("hibernate.ejb.entitymanager_factory_name", "PU_company_testowe2");
                                properties.put("jta-data-source", "java:/testowe2");
                                return properties;
                            }
                        }
                        
                        

                         

                        Error:

                         

                        22:02:51,604 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.subunit."-ear-1.0-SNAPSHOT.ear"."-ModelFacade-1.0-SNAPSHOT.jar".component.TestEntityManager.START: org.jboss.msc.service.StartException in service jboss.deployment.subunit."-ear-1.0-SNAPSHOT.ear"."-ModelFacade-1.0-SNAPSHOT.jar".component.TestEntityManager.START: Failed to start service
                                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_17]
                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_17]
                                at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_17]
                        Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
                                at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
                                at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85)
                                at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:116)
                                at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:130)
                                at org.jboss.as.ee.component.ComponentStartService.start(ComponentStartService.java:44)
                                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                                ... 3 more
                        Caused by: javax.ejb.EJBException: java.lang.UnsupportedOperationException: The application must supply JDBC connections
                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166)
                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230)
                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:333)
                                at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:56)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
                                at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
                                ... 9 more
                        Caused by: java.lang.UnsupportedOperationException: The application must supply JDBC connections
                                at org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:62)
                                at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:276)
                                at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
                                at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
                                at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.extractPhysicalConnection(ConnectionProxyHandler.java:82)
                                at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
                                at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
                                at com.sun.proxy.$Proxy125.prepareStatement(Unknown Source)
                                at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)
                                at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
                                at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)
                                at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1739)
                                at org.hibernate.loader.Loader.doQuery(Loader.java:828)
                                at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
                                at org.hibernate.loader.Loader.doList(Loader.java:2463)
                                at org.hibernate.loader.Loader.doList(Loader.java:2449)
                                at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279)
                                at org.hibernate.loader.Loader.list(Loader.java:2274)
                                at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:331)
                                at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1585)
                                at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:224)
                                at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:156)
                                at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:280)
                                at uk.co.techblue.jboss.auth.TestEntityManager.test(TestEntityManager.java:43)
                                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_17]
                                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_17]
                                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_17]
                                at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_17]
                                at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:130)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:73)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)
                                ... 18 more