Example usage for org.hibernate Session get

List of usage examples for org.hibernate Session get

Introduction

In this page you can find the example usage for org.hibernate Session get.

Prototype

Object get(String entityName, Serializable id);

Source Link

Document

Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

Usage

From source file:backendsw2.BackEndSW2.java

public static void taha() {
    Session se = databaseManager.SessionsManager.getSessionFactory().openSession();
    se.beginTransaction();/*  w ww .  ja va2s.  c  om*/
    Offer offer = (Offer) se.get(Offer.class, 2);
    //  emp.acceptFinishedTask(offer);
    //System.out.println(offer.getId());
    // emp.rejectFinishedTask(offer);
    Feedback f = new Feedback();
    f.setDate(LocalDateTime.MAX);
    f.setDescription("this is the test ");
    f.setOffer(offer);
    f.setRateValue(3);
    //emp.makeFeedback(f ,offer);
    // emp.rejectOffer(offer);
    //emp.acceptFinishedTask(offer);

    /*
       Account newaccount =  new Account();
            
    newaccount.setAccountState(1);
    newaccount.setFirstName("Z3bola");
    newaccount.setLastName("GON");
    newaccount.setPassword("PP");
    newaccount.setPhone("01148462144:^^:");
    newaccount.setUserName("USERNAME");
            
    newaccount.saveNewComplaint();
    */

    /*
    Complaint x = new Complaint();
    x.setId(3);
    x.setMessage("NEWMESSAGE 3");
    x.saveNewComplaint();
    */

    /* the second constructor
    Complaint com = new Complaint(1);
         System.out.println("main > " + com.getMessage());
    */

    /*
    OurSystem sys = OurSystem.getInstance();
    Freelancer free =  (Freelancer) sys.getAccount("asd", 0);
    System.out.println("main >> " + free.getBalance());
    System.out.println("main >> " + free.getProfile().getAverageHourCost());
     */
    /* @TahaMagdy: for insert 
      EmployerProfile empPro = new EmployerProfile();
      empPro.setId(3);
      empPro.setNumberOfTasks(3);
      empPro.setPicture("FUCK pic");
      empPro.setTotalMoney(80000.12);
            
            
      Employer emp = new Employer();
      emp.setUserName("tahamagdy");
      emp.setFirstName("Taha");
      emp.setLastName("Magdy");
      emp.setDate(LocalDateTime.MAX);
      emp.setPassword("taha");
      emp.setBirthDate("26/02/1996");
      emp.setCountry("FUCKING Egypt");
      emp.setVisaNumber("VISA: 222");
      emp.setPhone("01148462144");
      emp.setProfile( empPro);
            
      // Setting a Session
      Session session = databaseManager.SessionsManager.getSessionFactory().openSession();
      session.getTransaction().begin();
            
              
            
            
            
         // Updating Complaint
         session.save(emp);
         session.getTransaction().commit();
                 
         session.close();
            */
    /*
          * @TahaMagdy: Complaint Class testting...
         Session session = databaseManager.SessionsManager.getSessionFactory().openSession();
         session.getTransaction().begin();
         // Fetching complaint id = 2
         Complaint complaintDB = (Complaint) session.get(Complaint.class,2);
         System.out.println("complaintDB Testring: OK ->" + complaintDB.getMessage() );
         if ( !complaintDB.isSeen() ) {
            System.out.println("It is not seen" );
         }
         session.close();
            */

    /* @TahaMagdy: getTask testing
          OurSystem sys = OurSystem.getInstance();
          Task task = sys.getTask(1);
          System.out.print( "main,, Fetched category >> " +task.getCategory() );
            */
    /* @TahaMagdy: getOffer testing
          OurSystem sys = OurSystem.getInstance();
          Offer offer = sys.getOffer(2);
          System.out.println("offer description " + offer.getDescription());
            */
    /*
          * @TahaMagdy: testing AccountFactory
          * http 200 -> DONE
         AccountFactory facto = new AccountFactory();
         Freelancer free = (Freelancer) facto.getAccount("Freelancer");
         free.setBalance(1234);
         System.out.println(free.getBalance());
            */
    /*
          * @TahaMagdy: Adding a dummy Account for testing
         // Making a dummy account
         Account dummyAccount = new Account();
         dummyAccount.setId(12);
                 
         // Preparing a DB session
         Session session = databaseManager.SessionsManager.getSessionFactory().openSession();
         session.getTransaction().begin();
         // Inserting dummyAccount into DB
         session.save(dummyAccount);
         session.getTransaction().commit();
         session.close();
            */
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * Id??/*from w  w  w . j a  v a 2 s .  c  o m*/
 * @description   
 * @author  JiaCao
 * @param clazz
 * @param id
 * @return  
 */

public Object get(Class clazz, Integer id) {
    try {
        Session session = getSession();
        return session.get(clazz, id);
    } catch (RuntimeException re) {
        throw re;
    }
}

From source file:basedistribuida.connection.HibernateSession.java

protected <T> T getById(Class<T> clazz, int id) {
    Session session = sessionFactory.openSession();
    T generic;/*from   w  w  w  .j  av  a  2 s  .  c o  m*/
    try {
        session.beginTransaction();
        generic = session.get(clazz, id);
        session.getTransaction().commit();
    } finally {
        session.close();
    }
    return generic;
}

From source file:basedistribuida.connection.HibernateSession.java

protected <T> T getById(Class<T> clazz, String id) {
    Session session = sessionFactory.openSession();
    T generic;//from  w w w  . j a  va 2 s . c o m
    try {
        session.beginTransaction();
        generic = session.get(clazz, id);
        session.getTransaction().commit();
    } finally {
        session.close();
    }
    return generic;
}

From source file:baza.Broker.java

public Lekar vratiLekara(int lekarID) {
    Session session = Test.getSessionFactory().openSession();
    Lekar l = null;//from  w w w.ja v a 2  s .co m
    try {

        session.beginTransaction();
        l = (Lekar) session.get(Lekar.class, lekarID);
        session.getTransaction().commit();
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return l;
}

From source file:baza.Broker.java

public boolean sacuvajIzmeneLekara(Lekar l) {
    boolean uspesno = false;
    Session session = Test.getSessionFactory().openSession();
    try {/*from w w w.  ja v a  2s.c  o  m*/

        session.beginTransaction();
        Lekar lekar = (Lekar) session.get(Lekar.class, l.getLekarID());
        session.merge(l);
        session.getTransaction().commit();
        uspesno = true;
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return uspesno;
}

From source file:baza.Broker.java

public Pacijent vratiPacijenta(String jmbg) {
    Session session = Test.getSessionFactory().openSession();
    Pacijent p = null;// w ww.  j  av a 2 s.c om
    try {

        session.beginTransaction();
        p = (Pacijent) session.get(Pacijent.class, jmbg);
        session.getTransaction().commit();
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return p;
}

From source file:baza.Broker.java

public boolean sacuvajIzmenePacijenta(Pacijent p) {
    boolean uspesno = false;
    Session session = Test.getSessionFactory().openSession();
    try {//from ww w .  j  a v a  2s  .c o m

        session.beginTransaction();
        Pacijent pacijent = (Pacijent) session.get(Pacijent.class, p.getJMBGPacijenta());
        session.merge(p);
        session.getTransaction().commit();
        uspesno = true;
    } catch (HibernateException hibernateException) {
        session.getTransaction().rollback();
    } finally {
        session.close();
    }
    return uspesno;
}

From source file:bazydanych.CRUDTest.java

public void updateCar(Integer ID, int cena) {
    Session session = factory.openSession();
    Transaction tx = null;/*from www  . ja  v  a 2  s . c  o m*/
    try {
        tx = session.beginTransaction();
        Samochod car = (Samochod) session.get(Samochod.class, ID);
        car.setCena(cena);
        session.update(car);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null)
            tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
}

From source file:bazydanych.CRUDTest.java

public void deleteCar(Integer ID) {
    Session session = factory.openSession();
    Transaction tx = null;// ww w .j a va2 s . c  om
    try {
        tx = session.beginTransaction();
        Samochod car = (Samochod) session.get(Samochod.class, ID);
        session.delete(car);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null)
            tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
}