java hibernate session create

public class RegisterStory {
	private SysUserCDao sysUserCDao;
	@Test
	public void test() {
		SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session=sessionFactory.openSession();  
        Transaction tx = session.beginTransaction();
        String sql = "select * from sys_user where account='13167081006'";
        List list = session.createQuery(sql).list();
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
        	SysUserC sys_user = (SysUserC)iterator.next();
        	String user_id = sys_user.getUser_id();
        	System.err.println("user_id:"+user_id);
		}
        tx.commit();
        session.close();  
	}

}

 

你可能感兴趣的:(Hibernate)