首页 > 代码库 > Hibernate
Hibernate
<?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-configuration是连接配置文件的根元素 -->
<hibernate-configuration>
<session-factory>
<!-- 数据库连接信息-->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/dedecms</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- 以下是数据库连接池的配置 -->
<!-- 连接池最大和最小连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">1</property>
<!-- 超时时长 -->
<property name="hibernate.c3p0.timeout">5000</property>
<!-- 连接池最大缓存能存多少个Statement对象 -->
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- 数据库方言 -->
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- 自动建表 -->
<property name="hbm2ddl.auto">update</property>
<!-- 以下是所有数据表和实体类的映射文件 -->
<mapping resource="News.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是映射文件跟元素 -->
<hibernate-mapping package="hib">
<!-- 每个class对应一个持久化对象 -->
<class name="News" table="news_table">
<!-- 主键字段用id-->
<id name="id">
<!-- 主键生成策略 -->
<generator class="identiry" />
</id>
<!-- 普通字段用property -->
<property name="title"></property>
<property name="content"></property>
<pro
</class>
</hibernate-mapping>
package hib;
public class News {
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
private int id;
private String title;
private String content;
}
Hibernate