简体   繁体   English

如何在Spring Hibernate Oracle DB中使用WebLogic配置的连接池(具有JNDI名称)

[英]How to use WebLogic configured connection pool (with JNDI Name) in Spring Hibernate Oracle DB

I'm fairly new at this and I'm stuck. 我在这方面还很陌生,而且很困。 If someone could help, that would be great. 如果有人可以帮助,那就太好了。 My code right now uses inbuilt connection pool, how to change to Weblogic configured connection pool ? 我的代码现在使用内置连接池,如何更改为Weblogic配置的连接池? My code right now is as below: 我现在的代码如下:

hibernate-cfg.xml: 休眠-cfg.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"   "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property> 
        <property name="hibernate.connection.release_mode">after_transaction</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

<!-- Configure BLOB/CLOB settings in hibernate -->
<property name="hibernate.connection.SetBigStringTryClob">true</property>
<property name="hibernate.jdbc.batch_size">0</property>

<!--Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_query_cache">false</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="max_fetch_depth">3</property>

<!-- Bind the getCurrentSession() method to the thread. -->
        <property name="current_session_context_class">thread</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>


</session-factory>
</hibernate-configuration>

Hibernate Session Class that has the getSession method: 具有getSession方法的Hibernate Session类:

public class HibernateSession {


     public Session getSession() {

     Configuration configuration = new AnnotationConfiguration();

     configuration.setProperty("hibernate.connection.username", USERNAME);
     configuration.setProperty("hibernate.connection.password", PASSWORD);
     configuration.setProperty("hibernate.connection.url", DB_URL);
     configuration.configure("hibernate.cfg.xml");
     SessionFactory sessionFactory = configuration.buildSessionFactory();
     Session session = sessionFactory.getCurrentSession();

     return session;
     }
}

Hibernate version: 4.2.11.Final Weblogic: 10.3.6 休眠版本:4.2.11。最终Weblogic:10.3.6

您需要使用JNDI查找来查找通过WebLogic管理控制台配置的数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM