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

Java 如何在Spring Hibernate Oracle DB中使用WebLogic配置的连接池(具有JNDI名称),java,spring,oracle,hibernate,Java,Spring,Oracle,Hibernate,我对这方面还不太熟悉,我被卡住了。如果有人能帮忙,那就太好了。 我的代码现在使用内置连接池,如何更改为Weblogic配置的连接池?我现在的代码如下: hibernate-cfg.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://ww

我对这方面还不太熟悉,我被卡住了。如果有人能帮忙,那就太好了。 我的代码现在使用内置连接池,如何更改为Weblogic配置的连接池?我现在的代码如下:

hibernate-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版本:4.2.11.Final
Weblogic:10.3.6

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

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;
     }
}