List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:cd_modelos_dao.ReportesDeComprasDAO.java
public List<SuministrosCompra> consultarCompraSuministro(int id) { List<SuministrosCompra> lista = new LinkedList<>(); SessionFactory sf = HibernateUtil.getSessionFactory(); Session s = sf.openSession(); //Query q = s.createQuery("from SuministrosCompra where compraSuministros.getId() = "+ id +""); Query q = s.createQuery("from SuministrosCompra where id_compra_suministros = " + id); lista = q.list();//from ww w. ja v a 2s .co m for (SuministrosCompra sc : lista) { Suministros ser = (Suministros) s.get(Suministros.class, sc.getSuministros().getId()); sc.setSuministros(ser); } s.close(); return lista; }
From source file:cd_modelos_dao.ReportesDeVentasDAO.java
public List<PlantasVenta> consultarVentaPlanta(int id) { List<PlantasVenta> listado = new LinkedList<>(); SessionFactory sf = HibernateUtil.getSessionFactory(); Session s = sf.openSession(); Query q = s.createQuery("from PlantasVenta where id_ventas_planta = " + id); try {//ww w . j ava 2 s. c om listado = q.list(); for (int i = 0; i < listado.size(); i++) { Plantas p = (Plantas) s.get(Plantas.class, listado.get(i).getEtapasPlanta().getPlantas().getId()); Etapas p1 = (Etapas) s.get(Etapas.class, listado.get(i).getEtapasPlanta().getEtapas().getId()); EtapasPlanta ep = (EtapasPlanta) s.get(EtapasPlanta.class, new EtapasPlantaId(p.getId(), p1.getId())); ep.setPlantas(p); ep.setEtapas(p1); listado.get(i).setEtapasPlanta(ep); } } catch (Exception e) { System.out.println("Esta es la exception"); } s.close(); return listado; }
From source file:cd_modelos_dao.ServiciosDAO.java
public Servicios consultarServicioPorId(int id) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session s = sf.openSession(); Servicios ser = (Servicios) s.get(Servicios.class, id); s.close();/*from www .j ava2s. com*/ if (ser != null) { return ser; } return null; }
From source file:cd_modelos_dao.VentasDAO.java
public VentasPlanta consultarVentaPorId(int id) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session s = sf.openSession(); VentasPlanta ser = (VentasPlanta) s.get(VentasPlanta.class, id); List<PlantasVenta> listado = new LinkedList<>(); Query q = s.createQuery("from PlantasVenta where id_ventas_planta = " + id); try {//w w w. j ava 2s . co m listado = q.list(); } catch (Exception e) { System.out.println("____________________________________________________"); System.out.println(e); System.out.println("____________________________________________________"); } for (int i = 0; i < listado.size(); i++) { Plantas p = (Plantas) s.get(Plantas.class, listado.get(i).getEtapasPlanta().getPlantas().getId()); Etapas p1 = (Etapas) s.get(Etapas.class, listado.get(i).getEtapasPlanta().getEtapas().getId()); listado.get(i).setEtapasPlanta(new EtapasPlanta()); listado.get(i).getEtapasPlanta().setPlantas(p); listado.get(i).getEtapasPlanta().setEtapas(p1); } Set<PlantasVenta> listado2 = new HashSet<>(listado); ser.setPlantasVentas(listado2); s.close(); if (ser != null) { return ser; } return null; }
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
public E get(final long id, final LockOptions lockOptions) { Session currentSession = getCurrentSession(); Object result;/* www.j av a 2 s .c o m*/ if (lockOptions == null) { result = currentSession.get(this.entityClass, id); } else { result = currentSession.get(this.entityClass, id, lockOptions); } if (result != null) { return this.entityClass.cast(result); } else { return null; } }
From source file:ch.algotrader.dao.GenericDaoImpl.java
License:Open Source License
@Override public BaseEntityI get(final Class<? extends BaseEntityI> clazz, final long id) { return this.txTemplate.execute(txStatus -> { Session session = this.sessionFactory.getCurrentSession(); BaseEntityI result = (BaseEntityI) session.get(clazz, id); // initialize Entities if (result instanceof Security) { ((Security) result).accept(InitializationVisitor.INSTANCE, HibernateInitializer.INSTANCE); }/*ww w. java2 s . c o m*/ return result; }); }
From source file:ch.algotrader.dao.GenericDaoImpl.java
License:Open Source License
@Override public Object getInitializedCollection(final String role, final long id) { return this.txTemplate.execute(txStatus -> { SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) this.sessionFactory; CollectionPersister persister = sessionFactoryImpl.getCollectionPersister(role); // load the owner entity ClassMetadata ownerMetadata = persister.getOwnerEntityPersister().getClassMetadata(); Session session = this.sessionFactory.getCurrentSession(); Object owner = session.get(ownerMetadata.getEntityName(), id); // owner does not exist anymore so no point in loading the collection if (owner == null) { return null; }// w w w. ja va 2 s . co m // get the collection by it's property name Object col = ownerMetadata.getPropertyValue(owner, persister.getNodeName()); // if it is a PersistentCollection make sure it is initialized if (col instanceof PersistentCollection) { PersistentCollection collection = (PersistentCollection) col; if (!collection.wasInitialized()) { collection.forceInitialization(); } } return col; }); }
From source file:ch.flashcard.service.CardDeckService.java
License:Open Source License
public final CardDeck getCardDeckById(final int id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); CardDeckEntity cardDeckEntity = (CardDeckEntity) session.get(CardDeckEntity.class, id); CardDeck cardDeck = cardDeckMapper.mapToDomain(cardDeckEntity); transaction.commit();// w w w . ja v a2 s. co m session.close(); return cardDeck; }
From source file:ch.flashcard.service.CardDeckServiceImpl.java
License:Open Source License
public final CardDeckEntity getCardDeckById(final int id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); CardDeckEntity cardDeckEntity = (CardDeckEntity) session.get(CardDeckEntity.class, id); transaction.commit();/* ww w . jav a2 s .c o m*/ session.close(); return cardDeckEntity; }
From source file:ch.flashcard.service.CardService.java
License:Open Source License
public final Card getCardById(final int id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); CardEntity cardEntity = (CardEntity) session.get(CardEntity.class, id); Card card = cardMapper.mapToDomain(cardEntity); transaction.commit();/*from w ww . j a va2 s. c o m*/ session.close(); return card; }