hibernate 数据源在tomcat中配置

在hiberante中的hibernate.cfg.xml中内容:

<?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">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

<session-factory>
	<property name="dialect">
		org.hibernate.dialect.Oracle10gDialect
	</property>
              <!--加入下面这句代表数据源去找/market的-->   
	<property name="connection.datasource">java:comp/env/market</property>
	<mapping resource="com/market/po/Bank.hbm.xml" />
	<mapping resource="com/market/po/Account.hbm.xml" />
	<mapping resource="com/market/po/Firm.hbm.xml" />

</session-factory>

</hibernate-configuration>

 

这样hibernate的配置文件就完成了。

然后我们去tomcat下面的conf\Catalina\localhost\下增加market.xml。

这里我们需要注意的是,tomcat6和其以前的数据源配置文件是不同的。依次列出:

tomcat6:

<?xml version='1.0' encoding='utf-8'?>
<!--下面的所有"market"换成自己的工程名-->
<Context docBase="market" path="/market" privileged="true" reloadable="true" workDir="work/Catalina/localhost/market">
<!--下面的resource需要修改下name、username、password、url。如果使用的不是oracle数据库,修改下dirverClassName-->
  <Resource name="market" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="study_market" password="password" driverClassName="oracle.jdbc.driver.OracleDriver"
               url="jdbc:oracle:thin:@172.16.2.41:1521:gnnt"/> 
</Context>

 

tomcat6以下(tomcat5,4..):

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="market" path="/market" privileged="true" reloadable="true" workDir="work/Catalina/localhost/market">
  <Resource name="market" type="javax.sql.DataSource"/>
  <ResourceParams name="market">
    <parameter>
      <name>maxWait</name>
      <value>5000</value>
    </parameter>
    <parameter>
      <name>maxActive</name>
      <value>1500</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>password</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:oracle:thin:@172.16.2.41:1521:gnnt</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>oracle.jdbc.driver.OracleDriver</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <value>10</value>
    </parameter>
    <parameter>
      <name>username</name>
      <value>study_market</value>
    </parameter>	
  </ResourceParams>  
</Context>

 

你可能感兴趣的:(Hibernate)