I have a connection cache pool created and occasionally I get the Invalid stale connection object error. When I refresh the page and do the same operation it is working fine, means the exception is gone.
This is my config for the connection pool,
<bean id="myDataSource" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close">
<property name="connectionCachingEnabled" value="true" />
<property name="URL" value="${jdbcUrl-myapp}" />
<property name="user" value="${jdbcUsername-myapp}" />
<property name="password" value="${jdbcPassword-myapp}" />
<property name="connectionProperties">
<value>
oracle.jdbc.timezoneAsRegion=false
</value>
</property>
<property name="connectionCacheProperties">
<props merge="default">
<prop key="MinLimit">0</prop>
<prop key="MaxLimit">100</prop>
<prop key="InitialLimit">1</prop>
<prop key="ConnectionWaitTimeout">600</prop>
<prop key="InactivityTimeout">300</prop>
<prop key="ValidateConnection">true</prop>
</props>
</property>
</bean>
Basically you need to get ride of invalid/stale connection.
Try following set of properties:
<bean id="myDataSource" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close">
<property name="connectionCachingEnabled" value="true" />
<property name="URL" value="${jdbcUrl-myapp}" />
<property name="user" value="${jdbcUsername-myapp}" />
<property name="password" value="${jdbcPassword-myapp}" />
<property name="connectionProperties">
<value>
oracle.jdbc.timezoneAsRegion=false
</value>
</property>
<property name="connectionCacheProperties">
<props merge="default">
<prop key="MinLimit">0</prop>
<prop key="MaxLimit">100</prop>
<prop key="InitialLimit">1</prop>
<prop key="ConnectionWaitTimeout">600</prop>
<prop key="InactivityTimeout">300</prop>
<prop key="ValidateConnection">true</prop>
<prop key="testOnBorrow">true</prop>
<prop key="testOnReturn">true</prop>
<prop key="testWhileIdle">true</prop>
<prop key="validationQuery">select 1 from dual</prop>
<prop key="removeAbandoned">true</prop>
</props>
</property>
</bean>
Related
I have created two jobs, both will generate excel file.I need to generate multiple xlsx in parallel. But one job alone triggers at a time.
<bean id="breakFileXlsxTwo"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="com.citi.recon.quartz.BreakFileXlsxJobTwo" />
<property name="durability" value="true" />
</bean>
<bean id="breakFileXlsxTwoTrigger"
class="com.citi.recon.quartz.PersistableCronTriggerFactoryBean">
<property name="jobDetail" ref="breakFileXlsxTwo" />
<property name="cronExpression" value="0 0/10 * * * ?"/>
</bean>
<!-- cluster quartz, will only run in one server -->
<bean id="clusterquartzScheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="txManager" />
<property name="overwriteExistingJobs" value="true" />
<property name="autoStartup" value="true" />
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">AMLReconQuartzScheduler</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
</prop>
<prop key="org.quartz.jobStore.tablePrefix">qrtz_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">30</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
<prop key="org.quartz.jobStore.useProperties">true</prop>
</props>
</property>
<property name="jobFactory">
<bean class="com.citi.recon.quartz.AutowiringSpringBeanJobFactory" />
</property>
<property name="jobDetails">
<list>
<ref bean="userSynchJob"/>
<ref bean="breakFileDownloadJob"/>
<ref bean="breakFileXlsxTwo"/>
</list>
</property>
<property name="triggers">
<list>
<ref bean="userSynchJobTrigger"/>
<ref bean="breakFileDownloadJobTrigger"/>
<ref bean="breakFileXlsxTwoTrigger"/>
</list>
</property>
</bean>
In both jobs, i have given same 10 mins time interval.
In my job class,i am extending QuartzJobBean like below:
public class BreakFileXlsxDownloadJob extends QuartzJobBean
I am miagrating my database from MySql to H2 and I keep getting the error message
org.h2.jdbc.JdbcSQLException: Table "DEVICE" not found
Everything was mapped correctly and worked with MySql. I only changed the context.xml file to work with H2 and added a dependency for H2 in the Pom.xml file.
context.xml file:
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:~/dataStore2"/>
<property name="username" value="" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.entities" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<prop key="format_sql">true</prop>
<prop key="use_sql_comments">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
The Device class:
package com.entities;
#Entity
#Table(name="DEVICE")
public class Device {
...
}
You're missing
<prop key="hibernate.hbm2ddl.auto">create</prop>
in
<property name="hibernateProperties">
to force Hibernate to create schema based on entity classes if it is missing. You also need to change dialect from MySQL to H2:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.entities" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<prop key="format_sql">true</prop>
<prop key="use_sql_comments">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
Reference: Hibernate, Chapter 3. Configuration, Table 3.7. Miscellaneous Properties
below is my quatz integration with Spring but it is not working i.e. Job is not getting triggered . I can see quartz is checking MySQL database in few MS so that means connection with MYSQL is fine and also records are getting inserted in tables but Sysout mentioned in below class is not coming in console. please advice what could be root cause -
from Spring config XML
<bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="WaitForTasksToCompleteOnShutdown" value="true" />
</bean>
<bean id="exampleBusinessObjectJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<bean name="exampleBusinessObjectJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="name" value="exampleBusinessObjectJob"/>
<property name="jobClass" value="com.aexp.mars.job.ExampleJob"/>
</bean>
</property>
<property name="cronExpression" value="0 */1 * * * ?"/>
</bean>
<bean id="exampleBusinessObjectJob" class="com.aexp.mars.job.ExampleJob">
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="autoStartup" value="true"/>
<property name="triggers">
<list>
<ref bean="exampleBusinessObjectJobTrigger" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">MARS_SCHEDULER</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.scheduler.instanceId">10000</prop>
<prop key="org.quartz.scheduler.instanceId">600000</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop>
<prop key="org.quartz.threadPool.threadCount">3</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.useProperties">false</prop>
<prop key="org.quartz.jobStore.dataSource">marsDS</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.jobStore.clusterCheckinInterval">15000</prop>
<prop key="org.quartz.jobStore.maxMisfiresToHandleAtATime">20</prop>
<prop key="org.quartz.dataSource.marsDS.driver">com.mysql.jdbc.Driver</prop>
<prop key="org.quartz.dataSource.marsDS.URL">{server_url}</prop>
<prop key="org.quartz.dataSource.marsDS.user">{user_name}</prop>
<prop key="org.quartz.dataSource.marsDS.password">{password}</prop>
<prop key="org.quartz.dataSource.marsDS.maxConnections">10</prop>
<prop key="org.quartz.dataSource.marsDS.validationQuery">select 1</prop>
<prop key="org.quartz.plugin.shutdownHook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
<prop key="org.quartz.plugin.shutdownHook.cleanShutdown">false</prop>
</props>
</property>
<property name="taskExecutor" ref="myTaskExecutor" />
<property name="jobFactory">
<bean class="com.aexp.mars.job.MarsSpringBeanJobFactory"/>
</property>
</bean>
**Java class - **
public class ExampleJob {
private static final Logger LOG = LoggerFactory.getLogger(ExampleJob.class);
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job is running");
LOG.info("Job ran");
}
public void execute(JobExecutionContext ctx) throws JobExecutionException {
System.out.println("Job#1 is running");
LOG.info("Job ran");
}
}
Got the scenario . I changed the value of cron expression to run it in every 1 minute but it was still set to my previous value (i.e. early morning 3 AM) . i added below property and then new cron expression startd working ..
<property name="overwriteExistingJobs" value="true"/>
I have multiple data sources and the dynamic session mapping used to work fine when I used "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" Now I have upgraded my application to hibernate 4 and started using "org.springframework.orm.hibernate4.LocalSessionFactoryBean". For some reason hibernate is not able to map the tables from my second data source.
Here are my configs.
<bean id="DataSource1" class="org.apache.commons.dbcp.BasicDataSource"
autowire="byName" destroy-method="close">
<property name="driverClassName" value="$api{d1.jdbc.driver}" />
<property name="url" value="$api{d1.jdbc.url}" />
<property name="username" value="$api{d1.jdbc.username}" />
<property name="password" value="$api{d1.jdbc.password}" />
<property name="maxActive" value="$api{dbcp.maxActive}" />
<property name="maxWait" value="$api{dbcp.maxWait}" />
<property name="minIdle" value="$api{dbcp.minIdle}" />
<property name="maxIdle" value="$api{dbcp.maxIdle}" />
<property name="validationQuery" value="$api{dbcp.validationQuery}" />
<property name="testOnBorrow" value="true" />
</bean>
<bean id="d1SessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
autowire="byName">
<property name="dataSource" ref="DataSource1" />
<property name="annotatedClasses">
<list>
<value>com.class1</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.flush_before_completion">true</prop>
<prop key="hibernate.transaction.auto_close_session">true</prop>
</props>
</property>
</bean>
<bean id="d1Dao" class="com.DaoImpl"
autowire="byName">
<property name="sessionFactory" ref="d1SessionFactory"></property>
</bean>
And the second session definition is
<bean id="DataSource2" class="org.apache.commons.dbcp.BasicDataSource"
autowire="byName" destroy-method="close">
<property name="driverClassName" value="$api{d1.jdbc.driver}" />
<property name="url" value="$api{d1.jdbc.url}" />
<property name="username" value="$api{d2.jdbc.username}" />
<property name="password" value="$api{d2.jdbc.password}" />
<property name="maxActive" value="$api{dbcp.maxActive}" />
<property name="maxWait" value="$api{dbcp.maxWait}" />
<property name="minIdle" value="$api{dbcp.minIdle}" />
<property name="maxIdle" value="$api{dbcp.maxIdle}" />
<property name="validationQuery" value="$api{dbcp.validationQuery}" />
<property name="testOnBorrow" value="true" />
</bean>
<bean id="d2SessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
autowire="byName">
<property name="dataSource" ref="DataSource2" />
<property name="annotatedClasses">
<list>
<value>com.class2</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.flush_before_completion">true</prop>
<prop key="hibernate.transaction.auto_close_session">true</prop>
</props>
</property>
</bean>
<bean id="d2Dao" class="com.DaoImpl"
autowire="byName">
<property name="sessionFactory" ref="d2SessionFactory"></property>
</bean>
At run time when I do
Session session = this.sessionFactory.openSession() ;
The session always corresponds to d1SessionFactory even when dao is d2Dao.
Not sure what am I doing wrong here.
The same config worked fine when I was using "AnnotationSessionFactoryBean"
Help is appreciated.
The error I get is as follows
org.hibernate.hql.internal.ast.QuerySyntaxException: Class2 is not mapped [FROM Class2 WHERE user_id = :value0 AND active = :value1] at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180) at
org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110) at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93) at
org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:326) at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3252) at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3141) at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:694) at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:550) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287) at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235) at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101) at
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) at
org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119) at
org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:215) at
org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:193) at
org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1649)
I get this exception when i try to send a message to queue. My jms properties are set via spring application-context.Please find the applicationContext.xml properties set for the jms.
<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="lookupOnStartup" value="false"/>
<property name="jndiName">
<value>${jmsQueueConnectionFactory.jndiName}</value>
</property>
<property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">
${jndiTemplate.naming.factory}
</prop>
<prop key="com.sonicsw.jndi.mfcontext.domain">
${jndiTemplate.domain}
</prop>
<prop key="java.naming.provider.url">
${jndiTemplate.provider.url}
</prop>
<prop key="java.naming.security.principal">${jndiTemplate.security.principal}</prop>
<prop key="java.naming.security.credentials">${jndiTemplate.security.credentials}</prop>
</props>
</property>
</bean>
<bean id="requestsQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="lookupOnStartup" value="false"/>
<property name="jndiName">
<value>${requestsQueue.jndiName}</value>
</property>
<property name="proxyInterface" value="javax.jms.Destination"/>
</bean>
Am getting the exception as below:
org.springframework.jms.InvalidDestinationException: Unknown destination type - $Proxy115; nested exception is javax.jms.InvalidDestinationException: Unknown destination type - $Proxy115
I guess it happens because you hide your requestsQueue behind a lazy proxy, and your JMS implementation doesn't like it for some reason:
<property name="lookupOnStartup" value="false"/>
<property name="proxyInterface" value="javax.jms.Destination"/>
Try to remove these lines.