Hibernate创建步骤
(五大核心接口:Configuration/SessionFactory/Session/Transaction/Query)
1.新建工程,导入需要的jar包。
2.利用MyEclipse自动生成功能在工程中创建hibernate.cfg.xml配置文件和
HibernateSessionFactory.java工具类。生成的主要内容如下:
hibernate.cfg.xml:
1 <hibernate-configuration> 2 3 <session-factory> 4 <property name="connection.username">root</property> 5 <property name="connection.url"> 6 jdbc:mysql://localhost:3306/databasename 7 </property> 8 <property name="dialect"> 9 org.hibernate.dialect.MySQLDialect 10 </property> 11 <property name="myeclipse.connection.profile"> 12 dangdang 13 </property> 14 <property name="connection.password">root</property> 15 <property name="connection.driver_class"> 16 com.mysql.jdbc.Driver 17 </property> 18 <mapping resource="entity/User.hbm.xml" /> 19 20 </session-factory> 21 22 </hibernate-configuration>