List of usage examples for org.hibernate Session getNamedQuery
org.hibernate.Query getNamedQuery(String queryName);
From source file:com.fordoctor.sqlimpl.HibernateUtil.java
public List<?> getAllSeanse() { Session session = getSessionFactory().openSession(); session.beginTransaction();/*w w w . j a va 2s .c o m*/ Query query = session.getNamedQuery("Seanse.findAll"); List<Seanse> res = query.list(); session.getTransaction().commit(); try { session.close(); } catch (HibernateException he) { JOptionPane.showMessageDialog(null, he.getMessage()); } return res; }
From source file:com.forsrc.utils.ExportDb.java
License:Apache License
private static void executeNamedQuery(Session session, String queryName) { Transaction transaction = null;/*www . j a v a 2 s . c om*/ try { transaction = session.beginTransaction(); transaction.begin(); Query query = session.getNamedQuery(queryName); query.executeUpdate(); transaction.commit(); } catch (Exception e) { e.printStackTrace(); if (transaction != null) { transaction.rollback(); } //session.close(); //LogUtils.LOGGER.error(e.getMessage(), e); } }
From source file:com.fpmislata.daw.hibernateex1.Query.java
public static void main(String[] args) { Configuration config = new Configuration(); config.configure();/* ww w. ja v a2 s .co m*/ ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()) .buildServiceRegistry(); SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry); Session session = sessionFactory.openSession(); //org.hibernate.Query query =session.createQuery("SELECT p FROM Profesor p WHERE id=1001"); //--Query with name org.hibernate.Query query = session.getNamedQuery("findAllProfesores"); //---Query with name List<Profesor> profesores = query.list(); for (Profesor profesor : profesores) { System.out.println(profesor.toString()); } //---One row /* Profesor profesor = (Profesor) query.uniqueResult(); System.out.println(profesor.toString()); */ }
From source file:com.googlecode.hibernate.audit.HibernateAudit.java
License:Open Source License
public static Long getLatestAuditTransactionId(Session session) { Query query = session.getNamedQuery(SELECT_LATEST_AUDIT_TRANSACTION_ID); Long auditTransactionId = (Long) query.uniqueResult(); return auditTransactionId; }
From source file:com.googlecode.hibernate.audit.HibernateAudit.java
License:Open Source License
public static Long getLatestAuditTransactionIdByAuditLogicalGroupAndAfterAuditTransactionId(Session session, AuditLogicalGroup auditLogicalGroup, Long afterAuditTransactionId) { Query query = session.getNamedQuery( SELECT_LATEST_AUDIT_TRANSACTION_ID_BY_AUDIT_LOGICAL_GROUP_AND_AFTER_AUDIT_TRANSACTION_ID); query.setParameter("auditLogicalGroup", auditLogicalGroup); query.setParameter("afterAuditTransactionId", afterAuditTransactionId); Long auditTransactionId = (Long) query.uniqueResult(); return auditTransactionId; }
From source file:com.googlecode.hibernate.audit.HibernateAudit.java
License:Open Source License
public static Long getLatestAuditTransactionIdByEntity(Session session, AuditType auditType, String targetEntityId) {//from w w w . j a v a2 s .co m Query query = session.getNamedQuery(SELECT_LATEST_AUDIT_TRANSACTION_ID_BY_ENTITY); query.setParameter("auditType", auditType); query.setParameter("targetEntityId", targetEntityId); Long auditTransactionId = (Long) query.uniqueResult(); return auditTransactionId; }
From source file:com.googlecode.hibernate.audit.HibernateAudit.java
License:Open Source License
public static Long getLatestAuditTransactionIdByEntityAndAfterAuditTransactionId(Session session, AuditType auditType, String targetEntityId, Long afterAuditTransactionId) { Query query = session .getNamedQuery(SELECT_LATEST_AUDIT_TRANSACTION_ID_BY_ENTITY_AND_AFTER_AUDIT_TRANSACTION_ID); query.setParameter("auditType", auditType); query.setParameter("targetEntityId", targetEntityId); query.setParameter("afterAuditTransactionId", afterAuditTransactionId); Long auditTransactionId = (Long) query.uniqueResult(); return auditTransactionId; }
From source file:com.googlecode.hibernate.audit.HibernateAudit.java
License:Open Source License
public static Long getLatestAuditTransactionIdByProperty(Session session, AuditTypeField auditTypeField, String targetEntityId) {//from w ww .ja va 2s . c o m Query query = session.getNamedQuery(SELECT_LATEST_AUDIT_TRANSACTION_ID_BY_PROPERTY); query.setParameter("auditTypeField", auditTypeField); query.setParameter("targetEntityId", targetEntityId); Long auditTransactionId = (Long) query.uniqueResult(); return auditTransactionId; }
From source file:com.googlecode.hibernate.audit.HibernateAudit.java
License:Open Source License
public static Long getLatestAuditTransactionIdByPropertyAndAfterAuditTransactionId(Session session, AuditTypeField auditTypeField, String targetEntityId, Long afterAuditTransactionId) { Query query = session .getNamedQuery(SELECT_LATEST_AUDIT_TRANSACTION_ID_BY_PROPERTY_AND_AFTER_AUDIT_TRANSACTION_ID); query.setParameter("auditTypeField", auditTypeField); query.setParameter("targetEntityId", targetEntityId); query.setParameter("afterAuditTransactionId", afterAuditTransactionId); Long auditTransactionId = (Long) query.uniqueResult(); return auditTransactionId; }
From source file:com.googlecode.hibernate.audit.HibernateAudit.java
License:Open Source License
public static List<AuditObjectProperty> getModifiedAuditObjectProperties(Session session, List<AuditTypeField> auditTypeFieldsToCheck, String targetEntityId, Long afterAuditTransactionId) { Query query = session.getNamedQuery(SELECT_MODIFIED_AUDIT_OBJECT_PROPERTIES); query.setParameterList("auditTypeFields", auditTypeFieldsToCheck); query.setParameter("targetEntityId", targetEntityId); query.setParameter("afterAuditTransactionId", afterAuditTransactionId); List<AuditObjectProperty> result = (List<AuditObjectProperty>) query.list(); return result; }