標籤:word 驅動 資料 3.0 nec dial roo pre htm
配置範本: http://www.tutorialspoint.com/hibernate/hibernate_configuration.htm
1,核心設定檔
這個設定檔可以結合Hibernate的使用來記憶。
首先,在使用Hibernate的時候,需要先構造Configuration對象,然後用Configuration建造一個SessionFactory的一個具體實現。這就是一個抽象原廠模式。可以這樣來記憶:既然factory的具體資訊都來自configuration,那麼<session-factory>標籤包含在<hibernate-configuration>標籤裡就顯得理所應當了。
其次,<session-factory>標籤下的具體資訊。Hibernate本身是對jdbc的輕量封裝,那麼jdbc介面的資訊出現在<session-factory>標籤裡也就理所應當了。
關於hibernate.dialect。要知道,jdbc只是一個標準,平時對不同的資料庫進行jdbc串連,也要下載對應的jdbc驅動,這是因為不同的資料庫的內部實現不同。至於Dialect,官網描述為Represents a dialect of SQL implemented by a particular RDBMS.(代表了特定關聯式資料庫的sql實現) ,可以猜測dialect做的是關於sql語句的封裝。
最後,實體類對應檔的根節點是<hibernate-mapping>,下面可以配置一到多個<class>標籤,既可以一個實體類對應一個對應檔,也可以把多個實體類映射放在同一個檔案中。
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory> <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <!-- Assume test is the database name --> <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/db1 </property> <property name="hibernate.connection.username"> root </property> <property name="hibernate.connection.password"> pwd </property> <!-- List of XML mapping files --> <mapping resource="tbl1a.hbm.xml" /> <mapping resource="tbl1b.hbm.xml" /> </session-factory></hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping> <class name="com.pojo.Tbl1a" table="tbl1a"> <id name="id" type="int" column="id"></id> <property name="iachar" column="1achar" type="char" /> <property name="iaint" column="1aint" type="int" /> </class> </hibernate-mapping>
Hibernate最基礎配置的記憶方式