List of usage examples for org.hibernate SessionFactory openSession
Session openSession() throws HibernateException;
From source file:ayarlar.ayarlar.java
public void datagetir() { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session sesi = sf.openSession(); Transaction tr = sesi.beginTransaction(); List<Admin> ls = sesi.createQuery("from Admin").list(); for (Admin item : ls) { jTextField1.setText(item.getAdminAdi()); jTextField2.setText(item.getAdminSoyadi()); jTextField3.setText(item.getAdminMail()); jTextField4.setText(item.getAdminTelefon()); jTextField5.setText(item.getAdminKadi()); jPasswordField1.requestFocus();//from w w w. java2 s . c o m } tr.commit(); }
From source file:ayarlar.ayarlar.java
public void enter() { if (jPasswordField1.getText().equals("")) { JOptionPane.showMessageDialog(rootPane, "Ltfen Kullanc ifrenizi Giriniz "); } else {// ww w . j a va 2s . c om SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session sesi = sf.openSession(); Transaction tr = sesi.beginTransaction(); List<Admin> ls = sesi.createQuery("from Admin").list(); for (Admin item : ls) { String sifre = item.getAdminSifre(); String ssifre = MD5(jPasswordField1.getText()); if (sifre.equals(ssifre)) { JOptionPane.showMessageDialog(rootPane, "Bilgilerinizi Gncelleyebilirsiniz "); new yeniAyarlar().setVisible(true); } else { JOptionPane.showMessageDialog(rootPane, "Kullanc ifreniz Yanl"); jPasswordField1.setText(""); jTextField5.requestFocus(); } } } }
From source file:ayarlar.yeniAyarlar.java
public void datagetir() { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session sesi = sf.openSession(); Transaction tr = sesi.beginTransaction(); List<Admin> ls = sesi.createQuery("from Admin").list(); for (Admin item : ls) { jTextField6.setText(item.getAdminAdi()); jTextField7.setText(item.getAdminSoyadi()); jTextField1.setText(item.getAdminMail()); jTextField2.setText(item.getAdminTelefon()); jTextField3.setText(item.getAdminKadi()); jTextField4.requestFocus();/*from w w w. j a va 2 s .c o m*/ } tr.commit(); }
From source file:ayarlar.yeniAyarlar.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try {/*from ww w . ja v a2 s .c o m*/ if (jTextField4.getText().equals("") || jTextField5.getText().equals("")) { JOptionPane.showMessageDialog(rootPane, "Ltfen ifre Giriniz "); } else { String ysifre = jTextField4.getText(); String ytsifre = jTextField5.getText(); if (ysifre.equals(ytsifre)) { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session sesi = sf.openSession(); Transaction tr = sesi.beginTransaction(); Admin ad = new Admin(admin_id); ad.setAdminAdi(jTextField6.getText()); ad.setAdminSoyadi(jTextField7.getText()); ad.setAdminMail(jTextField1.getText()); ad.setAdminTelefon(jTextField2.getText()); ad.setAdminKadi(jTextField3.getText()); String ssifre = MD5(jTextField4.getText()); ad.setAdminSifre(ssifre); Date dt = new Date(); ad.setAdminTarih(dt); sesi.update(ad); tr.commit(); JOptionPane.showMessageDialog(rootPane, "Kaydetme lemi Baarl "); } else { JOptionPane.showMessageDialog(rootPane, "Ltfen ifreyi Kontrol Ediniz"); } } } catch (Exception e) { System.err.println("Kaydetme Hatas " + e); } }
From source file:banco.UsuarioDAO.java
public void addUsuario(Usuario usuario) { Transaction trns = null;/*from w w w.j a v a 2 s. co m*/ SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); try { trns = session.beginTransaction(); session.save(usuario); session.getTransaction().commit(); } catch (RuntimeException e) { if (trns != null) { trns.rollback(); } e.printStackTrace(); } finally { session.flush(); session.close(); } }
From source file:bd2.Test.Main.java
protected static Session getSession() { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); return session; }
From source file:beans.Driver.java
public static void main(String[] args) { Student s = new Student(); s.setId(4);//from www .ja va 2 s . co m s.setName("Amjad"); try { Configuration cf = new Configuration(); cf.configure("xml/hibernate.cfg.xml"); SessionFactory sf = cf.buildSessionFactory(); Session ses = sf.openSession(); ses.save(s); ses.beginTransaction().commit(); ses.evict(s); ses.close(); // // ses = sf.openSession(); // s = (Student)ses.get(Student.class, 1); // System.out.println("Name="+s.getName()); // System.out.println("Id="+s.getId()); } catch (Exception e) { e.printStackTrace(); } }
From source file:br.com.fatec.modelo.DAORepositorio.java
public DAORepositorio(Class<T> clazz, SessionFactory sf) { super();// w w w. j a v a 2 s . c o m this.clazz = clazz; this.session = sf.openSession(); }
From source file:br.com.machina.verbum.Main.java
License:Apache License
private static void addAdministratorUser() { AnnotationConfiguration configuration = new AnnotationConfiguration(); configuration.configure();/* w w w . j a v a2s .c o m*/ SessionFactory sessionFactory = configuration.buildSessionFactory(); Session session = null; Transaction transaction = null; try { session = sessionFactory.openSession(); transaction = session.beginTransaction(); User user = new User(); user.setName(ask("Please type your name:")); user.setLogin(ask("Please type your login:")); final String password = ask("Please type your password:"); user.setEmail(ask("Please type your e-mail:")); Sha1PasswordEncrypter encrypter = new Sha1PasswordEncrypter(); user.setPassword(encrypter.encrypt(password)); user.setAdministrator(true); session.save(user); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); } finally { if (session != null) { session.close(); } sessionFactory.close(); } }
From source file:br.com.sgejs.database.FabricaSessao.java
@Produces @RequestScoped//from ww w .j av a 2 s. co m public Session criaSessao(SessionFactory factory) { System.out.println("Abrir sessao*******"); return factory.openSession(); }