package com.biwit.hibernate;
import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Client {public static void main(String[] args) {Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();Session session = null;
try {
session = factory.openSession();session.beginTransaction();User user = new User();
user.setName("Zhang San");
user.setPassword("1");
user.setCreateTime(new Date());
user.setExpireTime(new Date());
session.save(user);session.getTransaction().commit();}catch(Exception e) {
e.printStackTrace();session.getTransaction().rollback();}finally {
if(null != session) {if(session.isOpen()) {
session.close();}}}}}
xxx.java
最新推荐文章于 2021-09-03 09:39:54 发布