`
dreamoftch
  • 浏览: 485695 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

hibernate配置

 
阅读更多

首先是hibernate.cxf.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 name="">
	 <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

  <!-- JDBC URL -->
  <property name="connection.url">jdbc:mysql://localhost/test?characterEncoding=utf-8</property>

  <!-- 数据库用户名-->
  <property name="connection.username">root</property>

  <!-- 数据库密码-->
  <property name="connection.password">root</property>
	<mapping
		resource="entity.Student.hbm.xml" />

</session-factory>
</hibernate-configuration>

 

 

然后测试方法:

		Configuration cfg = new Configuration().configure();
		Session session = cfg.buildSessionFactory().openSession(); 
		Transaction tx = session.beginTransaction(); 
		try {
                        session.get/save/delete/update......
			session.getTransaction().commit();
		} catch (HibernateException e) {
			session.getTransaction().rollback();
			e.printStackTrace();
		}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics