2012-03-13 24 views
8

我需要代碼將JNDI名稱添加到hibernate中的存檔連接池中。 我已經配置Jboss服務器中的連接池,JNDI名稱爲「EmployeeDB」如何以及何處爲Hibernate添加JNDI?

如何在hibernate.cfg.xml中配置?

如果我使用Hibernate 4 Final release,Plez給我提供hibernate.cfg.xml的代碼。

回答

14

在Jboss服務器中配置的數據源JDNI名稱由屬性hibernate.connection.datasource指定。

基本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="hibernate.connection.datasource">java:comp/env/jdbc/EmployeeDB</property> 

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

     <!-- Mapped annotated entity--> 
     <mapping class="org.hibernate.tutorial.domain.Event"/> 

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

謝謝...... 我知道力的生根粉hibernate.connection.datasource 現在在哪裏添加? 你的意思是在oracle-ds.xml中? 我應該修改哪些標籤? – bali208 2012-03-14 03:02:41

+0

'hibernate.connection.datasource'用於hibernate配置文件,默認文件名是'hibernate.cfg.xml' – 2012-03-14 17:14:02

+1

謝謝! 我試了一下! 它的工作! – bali208 2012-03-15 16:05:36

相關問題