Hibernate架構配置

來源:互聯網
上載者:User

標籤:tools   package   架構   builder   strong   junit   hbm.xml   自動建表   for   

 

 API

 

package com.hanqi.test;import static org.junit.Assert.*;import org.hibernate.SessionFactory;import org.hibernate.boot.registry.StandardServiceRegistryBuilder;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.junit.Test;public class Test01 {//測試Hibernate串連資料庫@Testpublic void test() {//1.擷取設定檔Configuration cfg  = new Configuration().configure();//2.註冊配置ServiceRegistry sr =new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();//3. 擷取Session-Factory(相當於JDBCd 串連)SessionFactory sf = cfg.buildSessionFactory(sr);System.out.println(sf);sf.close();}}

  設定檔

 

<?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.password">123456</property>  <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>  <property name="hibernate.connection.username">test0816</property>    <!--  資料庫方案-->  <property name="hibernate.default_schema">TEST0816</property>    <!--  資料庫方言-->  <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>    <!--  調試-->  <property name="hibernate.show_sql">true</property>  <property name="hibernate.format_sql">true</property>    <!-- 自動建表方式-->  <property name="hibernate.hbm2ddl.auto">create</property>    <!--  對應檔-->  <mapping resource="com/hanqi/entity/User.hbm.xml"/>   </session-factory></hibernate-configuration>

  

 ORM

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Generated 2016-11-7 14:39:56 by Hibernate Tools 3.4.0.CR1 --><hibernate-mapping>    <class name="com.hanqi.entity.User" table="T_USER">        <id name="userId" type="int">            <column name="USERID" />            <generator class="native" />        </id>        <property name="userName" type="java.lang.String">            <column name="USERNAME" length="20"  not-null="true" unique="true"/>        </property>        <property name="birthday" type="java.util.Date">            <column name="BIRTHDAY" sql-type="DATE"/>        </property>        <property name="money" type="double">            <column name="MONEY" sql-type="NUMBER" default="0" length="8" scale="2"/>        </property>        <property name="password" type="java.lang.String">         <column name="PASSWORD" length="10"/>         </property>    </class></hibernate-mapping>

 

 

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.