List of usage examples for org.hibernate SessionFactory getCurrentSession
Session getCurrentSession() throws HibernateException;
From source file:com.yf.kp.test.TestJenisPembayaran.java
License:Open Source License
/** * @param args the command line arguments *//*from www .jav a 2s . c om*/ public static void main(String[] args) { // TODO code application logic here AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(JenisPembayaran.class); config.configure("hibernate.cfg.xml"); new SchemaExport(config).create(true, true); SessionFactory sessionFactory = config.buildSessionFactory(); Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); JenisPembayaran jenisPembayaran = new JenisPembayaran(); jenisPembayaran.setNama("Fani Triastowo"); jenisPembayaran.setTipe("SPP"); jenisPembayaran.setNominal(50000.0); session.save(jenisPembayaran); session.getTransaction().commit(); }
From source file:com.yf.kp.test.TestKelas.java
/** * @param args the command line arguments *//* w w w . ja v a 2 s . co m*/ public static void main(String[] args) { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Kelas.class); config.addAnnotatedClass(Siswa.class); config.configure("hibernate.cfg.xml"); new SchemaExport(config).create(true, true); SessionFactory sessionFactory = config.buildSessionFactory(); Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); Kelas kelas1A = new Kelas(); kelas1A.setNama_kelas("1A"); Kelas kelas1B = new Kelas(); kelas1B.setNama_kelas("1B"); Kelas kelas2A = new Kelas(); kelas2A.setNama_kelas("2A"); Kelas kelas2B = new Kelas(); kelas2B.setNama_kelas("2B"); Kelas kelas3A = new Kelas(); kelas3A.setNama_kelas("3A"); Kelas kelas3B = new Kelas(); kelas3B.setNama_kelas("3B"); session.save(kelas1A); session.save(kelas1B); session.save(kelas2A); session.save(kelas2B); session.save(kelas3A); session.save(kelas3B); session.getTransaction().commit(); }
From source file:com.yf.kp.test.TestSiswa.java
/** * @param args the command line arguments *///from w ww . j av a 2s . c o m public static void main(String[] args) { // TODO code application logic here AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Siswa.class); config.configure("hibernate.cfg.xml"); new SchemaExport(config).create(true, true); SessionFactory sessionFactory = config.buildSessionFactory(); Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); Siswa fani = new Siswa(); fani.setNama("Fani Triastowo"); fani.setNis(1003040098); session.save(fani); session.getTransaction().commit(); }
From source file:com.yf.kp.test.TestTanggungan.java
License:Open Source License
/** * @param args the command line arguments *//*from w w w . j a va 2 s . com*/ public static void main(String[] args) { // TODO code application logic here AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Tanggungan.class); config.configure("hibernate.cfg.xml"); new SchemaExport(config).create(true, true); SessionFactory sessionFactory = config.buildSessionFactory(); Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); Tanggungan tanggungan = new Tanggungan(); tanggungan.setNis(1003040098); tanggungan.setNama("Fani Triastowo"); tanggungan.setKelas("1A"); tanggungan.setTanggungan("SPP"); session.save(tanggungan); session.getTransaction().commit(); }
From source file:com.zettsy.serverping.dao.PingDataImpl.java
@Override @Transactional//from w ww. j ava 2 s . co m public void addPingData(PingData pingData, SessionFactory sessionFactory) { Session session = sessionFactory.getCurrentSession(); Transaction trans = session.beginTransaction(); session.save(pingData); trans.commit(); }
From source file:controller.CustomerController.java
@Override public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { ModelAndView mv = new ModelAndView("customer"); String out = "Vpis uivatel: "; try {//from w w w. java 2 s . c o m SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml") .buildSessionFactory(); Session session = sessionFactory.getCurrentSession(); //Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); List result = session.createQuery("from Customer").list(); mv.addObject("customer", result); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } mv.addObject("message", out); return mv; }
From source file:controllers.personTypes.PersonTypeController.java
public List<PersonType> ConsultarPorNombre(String pNombre) { pNombre = pNombre + '%'; //Prep work//from ww w . ja v a 2 s. c o m SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction tx = session.beginTransaction(); Query query = session.createQuery("from PersonType where personTypeName like :nombre "); query.setParameter("nombre", pNombre); List<PersonType> personTypeList = query.list(); tx.commit(); sessionFactory.close(); return personTypeList; }
From source file:cyrille.hibernate.HHH2254Test.java
License:Apache License
public void test() throws Exception { AnnotationConfiguration annotationConfiguration = new HsqldbAnnotationConfiguration(); annotationConfiguration.addAnnotatedClass(PersistentObject.class); annotationConfiguration.configure(); SessionFactory sessionFactory = annotationConfiguration.buildSessionFactory(); {/*from ww w .ja v a2s.co m*/ Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); CompositeId compositeId = new CompositeId(); compositeId.setId1(new Long(1)); compositeId.setId2(new Long(2)); PersistentObject persistentObject = new PersistentObject(); persistentObject.setCompositeId(compositeId); persistentObject.setName("John Doe"); session.save(persistentObject); session.getTransaction().commit(); } { Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); CompositeId compositeId = new CompositeId(); compositeId.setId1(new Long(1)); compositeId.setId2(new Long(2)); PersistentObject persistentObject = (PersistentObject) session.get(PersistentObject.class, compositeId); assertEquals("John Doe", persistentObject.getName()); session.getTransaction().commit(); } }
From source file:cz.vsmie.example.hibernate.db.dao.impl.CartitemsDAOImpl.java
protected Session getSession() { return SessionFactory.getCurrentSession(); }
From source file:database.AbsDataLoader.java
License:Open Source License
/** * Main method used to load ABS data only. * On an existing database, this may duplicate data. * @param args: no parameters/*from w w w . j av a2 s . co m*/ */ public static void main(String[] args) { AnnotationConfiguration config = new AnnotationConfiguration(); config.setNamingStrategy(ImprovedNamingStrategy.INSTANCE); config.configure("database/hibernate.cfg.xml"); new SchemaExport(config).create(true, true); SessionFactory factory = config.buildSessionFactory(); Session session = factory.getCurrentSession(); session.beginTransaction(); LoadAbsData(session); session.getTransaction().commit(); }