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();
Configuration cfg=new Configuration().configure(); SchemaUpdate schemaUpdate = new SchemaUpdate(cfg); schemaUpdate.execute(true, true); System.out.println("OK");