hibernate

main,save
Configuration conf =new Configuration().configure();
SessionFactory sf=conf.buildSessionFactory();
Session sess=sf.openSession();
Transaction tx=sess.beginTransaction();

News a=new News();
a.setTitle("aaaaaaa");
a.setContent("aaaaaaaaaa");
sess.save(a);

tx.commit();
sess.close();
sf.close();




main,hbm.xml,createTable

Configuration cfg=new Configuration().configure();
SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);                
schemaUpdate.execute(true, true);
System.out.println("OK");

你可能感兴趣的:(Hibernate)