Hibernate在Tomcat 5.0.28下配数据源
hibernate的配置表部分内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.multi-DB.SingleMappingData">cityHibernate</property>
<property name="connection.datasource">java:comp/env/jdbc/test</property>
<property name="hibernate.session_factory_name">hibernate_jmzw</property>
<!-- <property name="transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>-->
<!--<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>-->
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="current_session_context_class">jta</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="jdbc.batch_size">50</property>
<property name="jdbc.fetch_size">100</property>
<property name="max_fetch_depth">1</property>
<property name="show_sql">true</property>
.......以下的是mapping
</session-factory>
</hibernate-configuration>
新建xml文件,
内容如下:(具体根据实际修改,比如数据源名name="jdbc/test",用户名密码URL等)
<?xml version='1.0' encoding='utf-8'?>
<Context debug="2" displayname="boss1.5_war" docBase="D:/Workspace/test/web" path="/test" reloadable="true" workDir="work\Catalina\localhost\test">
<Resource auth="Container" description="JNDI JDBC DataSource" name="jdbc/test" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/test">
<parameter>
<name>maxWait</name>
<value>50000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>40</value>
</parameter>
<parameter>
<name>password</name>
<value>123456</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@127.0.0.1:1521:SORA</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>username</name>
<value>test</value>
</parameter>
</ResourceParams>
</Context>
扔进%Tomcat%\conf\Catalina\localhost下即可。
就可以了。