Hibernate設定檔的書寫

來源:互聯網
上載者:User

標籤:user   version   style   session   實體類   ogg   3.0   nbsp   sage   

Hibernate主要設定檔
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">    <hibernate-configuration>        <session-factory>    <!-- 配置連結那個資料庫,怎麼串連 -->        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>    <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/hibernate</property>    <property name="hibernate.connection.username">root</property>    <property name="hibernate.connection.password">mysql</property>        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>    <!-- hibernate 其他資訊 -->    <property name="hibernate.show_sql">true</property>    <property name="hibernate.format_sql">true</property>    <!-- 設定我的hibernate執行的時候,是否要建立資料庫物件:例如表格      建立的方式:create:執行一次hibernate我就重新建立資料庫物件。      update:如果之前已經有這個表格了,那麼把這個表格裡面的結構更新成我這次要求的樣子。如果之前沒有這個表格,那麼我就重新建立一個。 -->    <property name="hibernate.hbm2ddl.auto">update</property>        <!--  讓session和本地線程綁定,確保我們的session對象唯一 -->    <property name ="hibernate.current_session_context_class">thread</property>                 <!--  引入我的對應檔 -->    <mapping resource="com/ambow/po/User.hbm.xml"/>            </session-factory>                    </hibernate-configuration>                    
  實體設定檔

 

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">        <hibernate-mapping>    <!-- 配置User實體類和表格t_user的映射關係        name:對應的是實體物件的全名稱    table:對應的是資料庫中表格的名字     -->     <class name="com.ambow.po.User" table="t_user">          <!-- 配置屬性和欄位的映射關係 -->     <!--  配置主鍵           name:實體屬性          column:欄位     -->     <id name="uid" column="uid">       <!--  設定主鍵自增   native :根據底層資料庫的種類去產生不同的主鍵自增方式。 -->       <generator class="native">                 </generator>          </id>     <!--  配置普通列          name:實體屬性          column:欄位           -->      <property name="username" column="username"></property>      <property name="sex" column="sex"></property>      <property name="address" column="address"></property>               </class>                </hibernate-mapping>

 

 

 

log4j日誌配置為檔案

## Hibernate, Relational Persistence for Idiomatic Java## License: GNU Lesser General Public License (LGPL), version 2.1 or later.# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.#### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### direct messages to file hibernate.log ####log4j.appender.file=org.apache.log4j.FileAppender#log4j.appender.file.File=hibernate.log#log4j.appender.file.layout=org.apache.log4j.PatternLayout#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### set log levels - for more verbose logging change ‘info‘ to ‘debug‘ ###log4j.rootLogger=warn, stdout#log4j.logger.org.hibernate=infolog4j.logger.org.hibernate=info### log HQL query parser activity#log4j.logger.org.hibernate.hql.ast.AST=debug### log just the SQL#log4j.logger.org.hibernate.SQL=debug### log JDBC bind parameters ###log4j.logger.org.hibernate.type=info#log4j.logger.org.hibernate.type=debug### log schema export/update ###log4j.logger.org.hibernate.tool.hbm2ddl=debug### log HQL parse trees#log4j.logger.org.hibernate.hql=debug### log cache activity ####log4j.logger.org.hibernate.cache=debug### log transaction activity#log4j.logger.org.hibernate.transaction=debug### log JDBC resource acquisition#log4j.logger.org.hibernate.jdbc=debug### enable the following line if you want to track down connection ###### leakages when using DriverManagerConnectionProvider ####log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace

 

  

 

Hibernate設定檔的書寫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.