title: Running Spring Hibernate Project in Tomcat as Standalone and Embedded Tomcat in STS IDE
body: <p>I have an issue when i run my application as a standalone web application using Tomcat. </p>
  
  <p>I use spring , struts 2 and hibernate . </p>
  
  <p>The weird part is when i run the application from the embedded tomcat in my STS IDE it is running fine.</p>
  
  <p>In both scenarios the web application runs fine but certain hibernate models are not getting initialized causing certain screens to fail when the application is run in the stand alone mode.</p>
  
  <p>Any help/direction would be greatly appreciated.</p>
  
  <p>Below is the exact error:</p>
  
  <p>Error in Pre-loading models or ppa_ids
      org.springframework.orm.hibernate3.HibernateQueryException: RealTimeModel is not mapped [select distinct forecast_model from RealTimeModel]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: RealTimeModel is not mapped [select distinct forecast_model from RealTimeModel]
          at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:656)</p>
  
  <p>applicationContext.xml </p>
  
  <pre><code>&lt;beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  &lt;!-- MyBatis setup start --&gt;
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
      &lt;property name="url" value="${jdbc.url}" /&gt;
      &lt;property name="username" value="${jdbc.username}" /&gt;
      &lt;property name="password" value="${jdbc.password}" /&gt;
  &lt;/bean&gt;
  &lt;context:property-placeholder location="classpath:jdbc.properties" /&gt;
  &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  &lt;bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;
      &lt;property name="transactionManager"&gt;
          &lt;ref bean="transactionManager" /&gt;
      &lt;/property&gt;
      &lt;property name="transactionAttributes"&gt;
          &lt;props&gt;
              &lt;prop key="create*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="insert*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="update*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="delete*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
      &lt;property name="configLocation" value="classpath:mybatis-config.xml"&gt;&lt;/property&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  &lt;bean id="permissionMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"&gt;
      &lt;property name="mapperInterface" value="com.guzmanenergy.dal.PermissionMapper"&gt;&lt;/property&gt;
      &lt;property name="sqlSessionFactory" ref="sqlSessionFactory"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="roleMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"&gt;
      &lt;property name="mapperInterface" value="com.guzmanenergy.dal.RoleMapper"&gt;&lt;/property&gt;
      &lt;property name="sqlSessionFactory" ref="sqlSessionFactory"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"&gt;
      &lt;property name="mapperInterface" value="com.guzmanenergy.dal.UserMapper"&gt;&lt;/property&gt;
      &lt;property name="sqlSessionFactory" ref="sqlSessionFactory"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="authorityMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"&gt;
      &lt;property name="mapperInterface" value="com.guzmanenergy.dal.AuthorityMapper"&gt;&lt;/property&gt;
      &lt;property name="sqlSessionFactory" ref="sqlSessionFactory"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="permissionService" class="com.guzmanenergy.service.impl.PermissionServiceImpl"&gt;
      &lt;property name="permissionMapper" ref="permissionMapper"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="authorityService" class="com.guzmanenergy.service.impl.AuthorityServiceImpl"&gt;
      &lt;property name="authorityMapper" ref="authorityMapper"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="userServiceTarget" class="com.guzmanenergy.service.impl.UserServiceImpl"&gt;
      &lt;property name="usermapper" ref="userMapper"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="userService" parent="txProxyTemplate"&gt;
      &lt;property name="target" ref="userServiceTarget"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;!-- MyBatis setup stop --&gt;
  &lt;!-- email setup start --&gt;
  &lt;bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt;
      &lt;property name="host" value="smtp.gmail.com" /&gt;
      &lt;property name="port" value="587" /&gt;
      &lt;!-- 25, 465, 587 --&gt;
      &lt;property name="username" value="support@getrident.com" /&gt;
      &lt;property name="password" value="Aragon101!" /&gt;
      &lt;property name="javaMailProperties"&gt;
          &lt;props&gt;
              &lt;prop key="mail.smtp.auth"&gt;true&lt;/prop&gt;
              &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;!--    &lt;bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt; --&gt;
  &lt;!--        &lt;property name="host" value="smtp.gmail.com" /&gt; --&gt;
  &lt;!--        &lt;property name="port" value="587" /&gt;  25, 465, 587 --&gt;
  &lt;!--        &lt;property name="username" value="GPMreporting@gmail.com" /&gt; --&gt;
  &lt;!--        &lt;property name="password" value="Guzman1234" /&gt; --&gt;
  &lt;!--        &lt;property name="javaMailProperties"&gt; --&gt;
  &lt;!--           &lt;props&gt; --&gt;
  &lt;!--                  &lt;prop key="mail.smtp.auth"&gt;true&lt;/prop&gt; --&gt;
  &lt;!--                  &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt; --&gt;
  &lt;!--           &lt;/props&gt; --&gt;
  &lt;!--        &lt;/property&gt; --&gt;
  &lt;!--    &lt;/bean&gt; --&gt;
  &lt;bean id="resetPasswordMailer" class="com.guzmanenergy.util.ResetPasswordMailer"&gt;
      &lt;property name="mailSender" ref="mailSender" /&gt;
  &lt;/bean&gt;
  &lt;bean id="sendEmail" class="com.guzmanenergy.util.SendMail"&gt;
      &lt;property name="mailSender" ref="mailSender" /&gt;
  &lt;/bean&gt;
  &lt;!-- email setup stop --&gt;
  &lt;!-- Spring + Hibernate Configuration --&gt;
  &lt;import resource="applicationContext-hibernate.xml"/&gt;
  &lt;!-- Curve Action Beans --&gt;
  &lt;bean id="curveDao" class="com.guzmanenergy.action.dao.Impl.CurveDaoImpl" scope="prototype"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref bean="Hibernate_sessionFactory"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="curveService" class="com.guzmanenergy.action.service.Impl.CurveServiceImpl" scope="prototype"&gt;
      &lt;property name="curveDao"&gt;
          &lt;ref bean="curveDao"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="curveAction" class="com.guzmanenergy.action.CurveAction_s2sh" scope="prototype"&gt;
      &lt;property name="curveService"&gt;
          &lt;ref bean="curveService"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;!-- Curve Action Beans End --&gt;
  &lt;!-- Beans for physical_longterm_main --&gt;
  &lt;bean id="physicalLongtermMainDao" class="com.guzmanenergy.action.dao.Impl.PhysicalLongtermMainDaoImpl" scope="prototype"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref bean="Hibernate_sessionFactory"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;!-- Beans for physical_longterm_main  End--&gt;
  &lt;!-- Real Time Model Beans --&gt;
  &lt;bean id="realTimeModelDao" class="com.guzmanenergy.action.dao.Impl.RealTimeModelDaoImpl" scope="prototype"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref bean="Hibernate_sessionFactory"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="realTimeModelService" class="com.guzmanenergy.action.service.Impl.RealTimeModelServiceImpl" scope="prototype"&gt;
      &lt;property name="realTimeModelDao"&gt;
          &lt;ref bean="realTimeModelDao"/&gt;
      &lt;/property&gt;
      &lt;property name="physicalLongtermMainDao"&gt;
          &lt;ref bean="physicalLongtermMainDao"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="RealTimeModelAction" class="com.guzmanenergy.action.RealTime_Model_Action" scope="prototype"&gt;
      &lt;property name="realTimeModelService"&gt;
          &lt;ref bean="realTimeModelService"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;!-- Real Time Model Beans --&gt;
  &lt;!-- forecast model download --&gt;
  &lt;bean id="ForcastModelDownloadAction" class="com.guzmanenergy.action.ForcastModelDownloadAction" scope="prototype"&gt;
      &lt;property name="realTimeModelService"&gt;
          &lt;ref bean="realTimeModelService"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;!-- forecast model download --&gt;
  &lt;!-- Spring + Hibernate Configuration End --&gt;
  </code></pre>
  
  <p></p>
  
  <p>applicationContext-hibernate.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                   http://www.springframework.org/schema/context
                   http://www.springframework.org/schema/context/spring-context-3.0.xsd
                   http://www.springframework.org/schema/aop
                   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                   http://www.springframework.org/schema/tx
                   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
  &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="ETRM_database"&gt;
      &lt;property name="locations"&gt;
          &lt;value&gt;classpath:jdbc.properties&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- 
  &lt;bean id="dataSource" destroy-method="close"
      class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
      &lt;property name="url" value="${jdbc.url}" /&gt;
      &lt;property name="username" value="${jdbc.username}" /&gt;
      &lt;property name="password" value="${jdbc.password}" /&gt;
  &lt;/bean&gt;
   --&gt;
  
  &lt;bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
      &lt;property name="url" value="${jdbc.url}" /&gt;
      &lt;property name="username" value="${jdbc.username}" /&gt;
      &lt;property name="password" value="${jdbc.password}" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="Hibernate_sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
      &lt;property name="mappingDirectoryLocations"&gt;
          &lt;list&gt;
              &lt;value&gt;classpath:com/guzmanenergy/action/domain&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;prop key="hibernate.cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/prop&gt;
              &lt;prop key="hibernate.cache.provider_configuration_file_resource_path"&gt;/ehcache.xml&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt;
              &lt;prop key="generate_statistics"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.region.factory_class"&gt;net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;!--
      &lt;property name="configLocation"&gt;
                  &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
              &lt;/property&gt; 
       --&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" scope="prototype"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref bean="Hibernate_sessionFactory"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;tx:advice id="ETRM_tx" transaction-manager="transactionManager"&gt;
      &lt;tx:attributes&gt;
          &lt;tx:method name="save*" read-only="false"/&gt;
          &lt;tx:method name="update*" read-only="false"/&gt;
          &lt;tx:method name="delete*" read-only="false"/&gt;
          &lt;tx:method name="*" read-only="true"/&gt;
      &lt;/tx:attributes&gt;
  &lt;/tx:advice&gt;
  
  &lt;aop:config&gt;
      &lt;aop:pointcut expression="execution(* com.guzmanenergy.action.service.Impl.*.*(..))" id="ETRM_perform"/&gt;
      &lt;aop:advisor advice-ref="ETRM_tx" pointcut-ref="ETRM_perform"/&gt;
  &lt;/aop:config&gt;
  </code></pre>
  
  <p></p>