Hi all,
I have an application using Spring 3, Hibernate 3, Tomcat 6 and Oracle.
All services and Daos are managered by spring IoC. All services are annotated by `@Transactional`. And an `OpenSessionInViewFilter` is defined in the web.xml
The application has a file upload function. it parses a excel spreadsheet and save it to the database.
before persistent, it verifies if each cell value is valid using the loop. so if there are 1000 rows, it will loop 1000 times.
in the loop there is a service dao method, which check's database by creating a query. when this method is called 297 times , the system got
ORA-01000: maximum open cursors exceeded
This makes sense because the oracle database has open_cursor=300;
I have added the `<prop key="hibernate.statement_cache.size">0</prop>`, but it did not work
i also added `poolPreparedStatements="false"` in the tomcat 6 context.xml datasource definition.
The Spring 3 localtransactionmanager supports plain hiberante code style, so i don't need use hiberantetemplate.
but is there a preparedstatemetn leak when using plain hbierante code style in Spring 3, or i missed something?
How can i solve this problem?
this is the Dao method
Code:@Repository public class SampleDaoImpl mplements SampleDao { .... .... public boolean isPositionOccupied(int se, int pos1, int pos2, int pos3,int pos4) { // TODO Auto-generated method stub session= sessionFactory.getCurrentSession(); String sql2 = "SELECT count(*) from table1 t1 and table2 t2 where ........."; Query q = session.createSQLQuery(sql2); q.setParameter("parameter1", se); q.setParameter("parameter2", pos1); ....... Object obj = q.uniqueResult(); if (Integer.valueOf(obj.toString())==0) return false; else return true; } }
This is the Service
Code:@Service @Transactional public class SampleDelegate implements SampleService{ @Autowired private SampleDao saDao; return saDao.isPositionOccupied((Integer)seMapStrInt.get(pos.getStorageName()), pos.getPosition1(), pos.getPosition2(), pos.getPosition3(), pos.getPosition4()); }
this is the web.xml
this is the hibernate-context.xmlCode:.... .... <filter> <filter-name>openSessionViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>openSessionViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> ... ...
Code:<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/datasource" resource-ref="true" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.connection.datasource">java:comp/env/jdbc/ktbDB</prop> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.statement_cache.size">0</prop> </props> </property> .... .... <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:annotation-driven transaction-manager="txManager"/>


Reply With Quote