1.jar包
2.hibernate.cfg.xml
3.model 配置
<?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="model.Tuser" table="Tuser"> <id name="scids" column="scids"> <generator class="uuid"></generator> </id> <property name="name" column="name"></property> </class> </hibernate-mapping>
4.测试实例
import model.Tuser; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class HibernateTest { /** * @param args */ public static void main(String[] args) { setup(); } private static void setup(){ Configuration fg = new Configuration().configure(); SessionFactory sessionFactory = fg.buildSessionFactory(); Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); Tuser uTuser = new Tuser(); uTuser.setName("aa"); session.save(uTuser); session.flush(); transaction.commit(); } }