以下的連線設定以 hibernate 3.0 以上版本為基礎, 除了基本的 hibernate 程式庫, 您還需要下載 PostgreSQL Driver, 才能順利執行.
由於 PostgreSQL 的資料型態與一般的 DB 略為不同, 建議在測試專案時可以將 "hbm2ddl.auto" 這個屬性設為 "true", 讓 hibernate 自動去對應最合適的資料型別, 並自動建立索引, sequence 等服務.
<!DOCTYPE hibernate-configuration PUBLIC
     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
     <!-- Database connection settings -->
     <property name="connection.driver_class">org.postgresql.Driver</property>
     <property name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>
     <property name="connection.username">inqgen</property>
     <property name="connection.password">inqgen</property>
 
     <!-- SQL dialect -->
     <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
     <!-- Enable Hibernate's automatic session context management -->
     <property name="current_session_context_class">thread</property>
     <!-- Echo all executed SQL to stdout -->
     <property name="show_sql">true</property>
 
     <!-- Drop and re-create the database schema on startup -->
     <property name="hbm2ddl.auto">create</property>
     <mapping resource="inqgen/Person.hbm.xml"/>
 </session-factory>
</hibernate-configuration>
0 意見:
張貼留言