内容来自http://www.cnblogs.com/sunniest/p/4539817.html
一、照例,导包
jar包来源 http://hibernate.org/orm/
二、配置hibernate.cfg.xml文件
-
- 在src目录下创建hibernate.cfg.xml文件(!!!必须是这个名字)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE hibernate-configuration PUBLIC 3 "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 4 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 5 <hibernate-configuration> 6 <session-factory> 7 8 <!-- 数据源 --> 9 <property name="connection.username">root</property> 10 <property name="connection.password">1234</property> 11 <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 12 <property name="connection.url">jdbc:mysql://localhost:3306/test</property> 13 14 <!-- configure the hibernate setting --> 15 <!-- transaction is supported by org.hibernate.dialect.MySQL5InnoDBDialect --> 16 <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> 17 <!-- show sql in the console --> 18 <property name="show_sql">true</property> 19 <!-- create and update the database automaticlly --> 20 <property name="hbm2ddl.auto">update</property> 21 22 <!-- javax.persistence.validation.mode默认情况下是auto的,就是说如果不设置的话它是会自动去你的classpath下面找一个 23 bean-validation**包,但是找不到,所以beanvalitionFactory错误 --> 24 <property name="javax.persistence.validation.mode">none</property> 25 26 </session-factory> 27 </hibernate-configuration>
时间: 2024-10-10 23:17:12