我正在为我的应用程序使用hibernate和oracle隐式连接池
数据源配置
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="jdbc:oracle:thin:@localhost:1521/xe" />
<property name="user" value="abc" />
<property name="password" value="abc" />
<property name="connectionCachingEnabled" value="true"></property>
<property name="connectionCacheProperties">
<props>
<prop key="MinLimit">10</prop>
<prop key="MaxLimit">20</prop>
<prop key="InitialLimit">10</prop>
<prop key="ConnectionWaitTimeout">200</prop>
<prop key="PropertyCheckInterval">1</prop>
</props>
</property>
</bean>
EntityManager配置
<bean id="entityManagerFactoryDefault"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="MaterializedView" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/jpa-persistence.xml" />
</bean>
主要方法
public static void main(String[] args) throws InterruptedException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/META-INF/spring/jpa-context.xml");
EntityManagerFactory entityManagerFactory = (EntityManagerFactory) applicationContext.getBean("entityManagerFactoryDefault");
System.out.println("+++++++++++++++++");
entityManagerFactory.close();
Thread.sleep(10000);
}
我不明白为什么即使在关闭entityManagerFactory后连接也没有关闭。 当我查询
select username,last_call_et "last call", status,PREV_HASH_VALUE from v$session WHERE status = 'INACTIVE';
我看到连接处于INACTIVE状态,其计数与connectionCacheProperties中指定的初始限制相同。 我的代码有问题,或者这是实际行为吗?