1 <?xml version=‘1.0‘ encoding=‘utf-8‘?> 2 <!DOCTYPE hibernate-configuration PUBLIC 3 "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 4 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 5 <hibernate-configuration> 6 <session-factory> 7 <property name="connection.driver_class">oracle.jdbc.OracleDriver</property> 8 <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> 9 <property name="connection.username">zc</property> 10 <property name="connection.password">zc</property> 11 <!-- 输出所有 SQL 语句到控制台。 --> 12 <property name="hibernate.show_sql">true</property> 13 14 <!-- 在 log 和 console 中打印出更漂亮的 SQL。 --> 15 <property name="hibernate.format_sql">true</property> 16 <!-- 自动生成数据表,update/create --> 17 <property name="hbm2ddl.auto">update</property> 18 <!-- 方言 --> 19 <property name="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect</property> 20 <!-- 关联小配置 --> 21 <mapping resource="cn/happy/test/Student.hbm.xml"/> 22 </session-factory> 23 </hibernate-configuration>
hibernate.cfg.xml大配置。
1 <?xml version=‘1.0‘ encoding=‘utf-8‘?> 2 <!DOCTYPE hibernate-mapping PUBLIC 3 "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 4 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 5 6 <hibernate-mapping package="cn.happy.entity"> 7 <!-- 实体类和数据库表 --> 8 <class name="Student" table="Student"> 9 <id name="id" type="int" column="id"> 10 </id> 11 <property name="name" type="string" column="name"/> 12 <property name="age" type="int" column="age"/> 13 </class> 14 </hibernate-mapping>
Student.hbm.xml小配置。
时间: 2024-10-11 00:39:41