簡體   English   中英

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

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

我在這方面還很陌生,而且很困。 如果有人可以幫助,那就太好了。 我的代碼現在使用內置連接池,如何更改為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類:

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

休眠版本:4.2.11。最終Weblogic:10.3.6

您需要使用JNDI查找來查找通過WebLogic管理控制台配置的數據源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM