配置hibernate例子

一、hiberbate.cfg.xml

<?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>
 <!-- dataBase connection settting -->
 <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
  <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
  <!-- 数据库用户名 -->
 <property name="connection.username">root</property>
 <property name="connection.password">admin</property>
 <!-- jdbc connection pool -->
 <property name="connection.pool_size">1</property>
 <!--  dataBase dialect -->
 <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
 <property name="hbm2ddl.auto">create</property>
 <property name="show_sql">true</property>
 <mapping resource="com/documain/Company.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://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.documain">

 <class name="Company" table="company" catalog="test">

  <id name="id" column="id"  type="java.lang.Long">    

<generator class="increment" />   

</id>  

 <property name="name" type="java.lang.String">  

   <column name="name"></column>  

 </property>  

 <property name="url" type="java.lang.String" >

  <column name="url" length="25"/>   

</property>

  <property name="creationDate"  type="java.util.Date">

  <column name="creation_date" />   

</property>  

</class>

</hibernate-mapping>

 

posted @ 2013-09-26 16:09  吴伟都  阅读(196)  评论(0编辑  收藏  举报