hibernate Annotation 注解形式 实例 事务 hibernate.cfg.xml
实体类:
import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.AnnotationConfiguration;import org.hibernate.cfg.Configuration;public class test1 {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubfoo s = new foo;s.setId(1);s.setName(2);S.settotal(ss);Configuration configuration = new AnnotationConfiguration();SessionFactory sessionFactory = configuration.buildSessionFactory();Session session = sessionFactory.openSession();//用事务方式储存\session.beginTransaction();session.save(s);session.getTransaction().commit();session.close();//sessionFactory也要关闭sessionFactory.close();}}