<?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="connection.driver_class">oracle.jdbc.OracleDriver</property>
<!-- jdbc:oracle:thin:@10.162.128.131:1521:ybrsjhk -->
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">hr</property>
<property name="connection.password">Hr5391861</property> <!-- 方言 -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property> <!-- 控制台显示SQL -->
<property name="show_sql">true</property> <!-- 自动更新表结构 -->
<property name="hbm2ddl.auto">update</property> <mapping resource="com/java1234/model/Book.hbm.xml"/>
</session-factory> </hibernate-configuration>
该工程的目录如下:
该工程的压缩包放在文件管理下。
其中对应的实体类Book.java的配置文件如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.java1234.model"> <class name="Book" table="t_book">
<!-- 下面的column如果没有写则数据库中对应的
字段名就跟name属性的值一直,如果写了则就是
自己录入的column属性的值。这里的id指的是主键为bookId,
下面的property标签则是普通的字段。
-->
<id name="bookId" column="book_id">
<generator class="native"></generator>
</id> <property name="bookName" length="40"></property>
<property name="price" type="float"></property>
<property name="publishDate" type="date"></property>
<property name="author" length="40"></property>
<property name="introduction" type="text"></property>
<property name="bookPic" type="blob"></property>
</class> </hibernate-mapping>