0
在hibernate中做實時項目需要連接代碼還是連接池來連接數據庫或hibernate.config.xml就夠了?在hibernate中做實時項目需要連接代碼還是連接池來連接數據庫
在hibernate中做實時項目需要連接代碼還是連接池來連接數據庫或hibernate.config.xml就夠了?在hibernate中做實時項目需要連接代碼還是連接池來連接數據庫
使用Hibernate,您不需要編寫連接代碼,但您需要配置Hibernate將使用的連接併爲您生成連接代碼。
任何使用Hibernate作爲ORM工具的實時項目都必須指定連接屬性。另外實時項目不會重新發明輪子,而是使用現成的連接池,如c3po。
下面的配置預訂購幫助您瞭解
<?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.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:MKYONG</property>
<property name="hibernate.connection.username">mkyong</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.default_schema">MKYONG</property>
<property name="show_sql">true</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<mapping class="com.mkyong.user.DBUser"></mapping>
</session-factory>
</hibernate-configuration>
您可以在此鏈接找到整個例如:http://www.mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/