首先是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(); }
相关推荐
Hibernate配置文件中配置各种数据库的driver、URL
hibernate配置,详细的讲了hibernate用的配置文件和方法,可以哦
Hibernate配置文件hibernate.cfg.xml中配置信息详解!
逆向生成hibernate配置文件逆向生成hibernate配置文件逆向生成hibernate配置文件逆向生成hibernate配置文件逆向生成hibernate配置文件逆向生成hibernate配置文件
hibernate配置文件 里面提供了连接数据库 数据库使用的方言 是否打印SQL语句 sql语句的格式 以及对象-关系映射文件的地址等
使用反射机制修改加载到内存的Hibernate配置文件,使用该方法可以将数据库的配置信息提取到别的路径下。
struts2+spring+hibernate 配置文件struts2+spring+hibernate 配置文件
hibernate--5.Hibernate配置文件详解
SpringMVC+Spring+hibernate配置
hibernate 配置 C3P0 连接池
如何使用用myeclipse自动生成hibernate配置文件
springboot2.0多数据源集成hibernate配置hibernateDaoSupport, dao层继承hibernateDaoSupport, 不使用jpa方式。
Hibernate配置文件Hibernate配置文件Hibernate配置文件
hibernate所以配置以及简单的介绍
hibernate的配置介绍,在myeclipse中配置hibernate,hibernate已经在myeclipse中了,创建工程,然后在工程中添加hibernate框架,一些设置
JAVA 使用hibernate配置实例,包括普通java工程版本(不是web工程)和maven配置使用hibernate版本。
Hibernate配置详解,详细描述了Hibernate的配置文件,一对一 一对多,多对多的单双向配置详解。
NULL 博文链接:https://hi-beijing.iteye.com/blog/1174299
帮助大家在配置hibernate方面提供支持