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

时间:2014-08-19 01:43:18

标签: java spring oracle hibernate

我在这方面相当新,而且我被困住了。如果有人可以提供帮助,那就太好了。 我的代码现在使用内置连接池,如何更改为Weblogic配置的连接池?我现在的代码如下:

冬眠-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>

具有getSession方法的Hibernate Session Class:

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

1 个答案:

答案 0 :(得分:1)

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