I got the production DB dump and am able to reproduce same error with WildFly 11 and MySql installed on my machine : Error is reproduced when login() method is called from JSF Managed bean.
org.hibernate.exception.SQLGrammarException: could not prepare statement.
Debugged the Web App and here are some observations with sysouts →
2019-01-22 19:21:09 INFO client:51 - JBoss EJB Client version 4.0.7.Final
2019-01-22 19:21:09 INFO stdout:71 - HOTSWAP AGENT: 19:21:09.225 INFO (org.hotswap.agent.plugin.wildfly.el.WildFlyELResolverPlugin) - Patched org.jboss.el.cache.BeanPropertiesCache2019-01-22 19:21:09 INFO stdout:71 - HOTSWAP AGENT: 19:21:09.245 INFO (org.hotswap.agent.plugin.wildfly.el.WildFlyELResolverPlugin) - Patched org.jboss.el.cache.BeanPropertiesCache$SoftConcurrentHashMap
2019-01-22 19:21:32 INFO stdout:71 - in intialize() method of UserManagementServiceSlsb
Here UserManagementServiceSlsb stateless session bean has been created
2019-01-22 19:21:32 INFO stdout:71 - entityManager injected →
Next EntityManager is injected by Container.
2019-01-22 19:21:32 INFO stdout:71 - entitymanager → org.jboss.as.jpa.container.TransactionScopedEntityManager@413acfaf
2019-01-22 19:21:32 INFO stdout:71 - this.entityManager.getFlushMode()AUTO
Default flush mode : Auto
2019-01-22 19:21:32 INFO stdout:71 - daoFactory-> com.itsys.erp.server.dal.JPADAOFactory@3a1aee46
2019-01-22 19:21:32 INFO stdout:71 - in UserManagementServiceImpl(DAOFactory daoFactory) constructor
2019-01-22 19:21:33 INFO stdout:71 - executing query by calling getSingleResult()
JPQL executed by Query.getSingleResult() method;
2019-01-22 19:21:33 INFO stdout:71 - Hibernate: select userdetail0_.user_id as user_id1_21_, userdetail0_.last_activity_date as last_act2_21_, userdetail0_.online_status as online_s3_21_, userdetail0_.password_change_date as password4_21_, userdetail0_.password as password5_21_, userdetail0_.user_email_id as user_ema6_21_, userdetail0_.user_name as user_nam7_21_ from user_detail userdetail0_ where userdetail0_.user_name=?
Above sql query generated by Hibernate is okay and can be executed in MySql.
Next getting SQLGrammarException
19:21:33,662 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-5) SQL Error: 42102, SQLState: 42S02
19:21:33,662 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-5) Table “USER_DETAIL” not found; SQL statement:2019-01-22 19:21:33 ERROR stderr:71 - javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
The difference between running the Junit Tests and Web App is that EJBs are not in the picture when runing Junit Tests, instead am creating EntityManagerFactory and getting EntityManager from it. And JPQL is returning results.
Do I need to test EJB? I tried with Arquillian, but it’s a bit complex and time consuming to implement. But I don’t think testing EJBs would solve the problem. Any other framework do you know to test EJBs?
What other configuration should I check ?
Thanks.