T t;
Configuration cfg = new Configuration();
cfg.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
SessionFactory sessionFactory = cfg.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
session.beginTransaction();
t=(T) session.get(entityClass, id);
session.getTransaction().commit();
sessionFactory.close();
时间: 2024-10-08 02:09:37