hi all,
i have a query in my application. it runs well, but if i disable the network access in my laptop, the application blocks and tries to run the query and take a long time and never throws timeout exception or any other exception. I know that the application blocks in the query implementation from the log files and from the eclipse debugger. I want to set my own timeout period for the query or any other way to detect that something bad has happened to the connection.I have tried set timeouts in the query hint and in the persistence.xml but no vain.
note : when i re enable the network access in my laptop the query runs successfully and the application execution continues normally,otherwise the application will block trying to run the query till the network is enabled.
is this possible in j2se or just for jee environments?
i am using
1-hibernate 4.1
2-ojdbc6.jar
3-oracle 10g remote db server
4-c3p0 connection pool
this getResultList() documentation
http://docs.oracle.com/javaee/6/api/javax/persistence/Query.html#getResultList%28%29this is how i create my entity manager
Code:
emf = Persistence.createEntityManagerFactory("EntitiesGenerator_2");
em = emf.createEntityManager();
and this is my query
Code:
try{
results=em.createNamedQuery("findActiveCyclesInThisMoment"). setHint("javax.persistence.query.timeout", "3"). getResultList();
}
catch(Exception ex){
ex.printStackTrace();
}
and this my persistence.xml properties
Code:
<property name="javax.persistence.query.timeout" value="3" />
<property name="hibernate.timeout" value="3" />
<property name="hibernate.connection.timeout" value="3" />
<property name="hibernate.connection.driver_class " value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.user" value="lba" />
<property name="hibernate.connection.password" value="lba" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@192.168.1.2:1521:edafadb1" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.show_sql" value="false"/>
<property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
<property name="hibernate.c3p0.acquire_increment" value="1"/>
<property name="hibernate.c3p0.idle_test_period" value="3000"/>
<property name="hibernate.c3p0.min_size" value = "1"/>
<property name="hibernate.c3p0.max_size" value = "4"/>
<property name="hibernate.c3p0.max_statements" value = "50"/>
<property name="hibernate.c3p0.timeout" value = "3"/>
thanks in advance :)