hibernate.cfg.xml 配置 和 java代码配置
hibernate.cfg.xml 配置:
<?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="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/mytest</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="domain/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Configuration configuration = new Configuration().configure();
java代码配置:
Configuration configuration = new Configuration().addClass(domain.Student.class).
setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
.setProperty("hibernate.connection.driver_class", "org.gjt.mm.mysql.Driver")
.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/mytest")
.setProperty("hibernate.connection.username", "root")
.setProperty("hibernate.connection.password", "123456");
hibernate.cfg.xml 配置 和 java代码配置
原创
©著作权归作者所有:来自51CTO博客作者xzlAwin的原创作品,请联系作者获取转载授权,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Hibernate - hibernate.cfg.xml配置文件详解
Hibernate 配置文件主要用于配置数据库连接和 Hibernate 运行时所需的各种属性。每个 Hibernate 配置文件对应一个 Configuration
Hibernate配置文件 hibernate.cfg.xml hibernate 数据库 sql -
Hibernate中配置文件hibernate.cfg.xml详解
Hibernate的描述文件可以是一个properties属性文件,也可以是一个xml文件。
Hibernate xml 配置 hibernate bc