导入Hibernate框架 步骤: 小列子:JAVA package com.lovo.test; import com.lovo.dao.UserDAO; import com.lovo.po.UserPO; public class TestMain { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub UserPO user = new UserPO(); user.setName("zbz"); user.setPassword("frjjno3"); UserDAO dao = new UserDAO(); dao.deleteUser(user); } } package com.lovo.po; public class UserPO { private int id; private String name; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } package com.lovo.dao; import org.hibernate.Session; import org.hibernate.Transaction; import com.lovo.db.HibernateSessionFactory; import com.lovo.po.UserPO; public class UserDAO { public void addUser(UserPO user){ Session session = HibernateSessionFactory.getSession(); Transaction transaction = session.beginTransaction(); session.save(user); transaction.commit(); session.close(); } public void deleteUser(UserPO user){ Session session = HibernateSessionFactory.getSession(); Transaction transaction = session.beginTransaction(); session.delete(user); transaction.commit(); session.close(); } } 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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.url"> jdbc:mysql://localhost:3306/test </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property>//使用的语言 <property name="myeclipse.connection.profile">test64</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="show_sql">true</property> <mapping resource="com/lovo/po/UserPO.hbm.xml" />//映UserPO </session-factory> </hibernate-configuration> UserPO.hbm.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping> <class name="com.lovo.po.UserPO" table="t_user">//这个bean对应的表 <id name="id" column="f_id" type="int"> <generator class="increment"></generator>//主键采用什么方式递增 </id>//id必须有,一个bean里面必须有一个对应数据库表里的ID <property name="name" column="f_name" type="java.lang.String"></property>//bean里面对应表里面的列类型是什么 <property name="password" column="f_password" type="java.lang.String"></property> </class> </hibernate-mapping>