Java Code Examples for org.hibernate.Session.getNamedQuery()

The following are Jave code examples for showing how to use getNamedQuery() of the org.hibernate.Session class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: oscm   File: HibernateIndexer.java   View Source Code Vote up 6 votes
/**
 * It must be stupid simply indexing the passed domain objects without
 * additional BL and additional queries.<br>
 *
 * Returns the list of products to be indexed. In case if the template
 * product is updated, beside of the index fields for the this product also
 * these for broker, reseller and customer specific copies must be updated
 * as well.
 */
private List<Product> getProductAndCopiesForIndexUpdate(Product product,
        Session session) {
    List<Product> productsToUpdate = new ArrayList<>();
    if (!product.isCopy()) {

        org.hibernate.Query query = session
                .getNamedQuery("Product.getProductsForTemplateIndexUpdate");
        query.setParameter("template", product);
        query.setParameterList("state",
                EnumSet.of(ServiceStatus.ACTIVE, ServiceStatus.INACTIVE,
                        ServiceStatus.SUSPENDED, ServiceStatus.OBSOLETE));
        query.setParameterList("type",
                EnumSet.of(ServiceType.PARTNER_TEMPLATE,
                        ServiceType.CUSTOMER_TEMPLATE));
        productsToUpdate.addAll(
                ParameterizedTypes.list(query.list(), Product.class));
    }
    return productsToUpdate;
}
 
Example 2
Project: Celebino   File: GenericDao.java   View Source Code Vote up 6 votes
public List<T> getAll(String namedQuery) throws SQLException {
	logger.info("Init abstract GetAll to: " + namedQuery);

	Session session = HibernateUtil.getSessionFactory().openSession();
	List<T> list = null;

	try {
		session.beginTransaction();
		Query query = session.getNamedQuery(namedQuery);
		list = (List<T>) query.list();
		session.getTransaction().commit();

	} catch (HibernateException hibernateException) {
		session.getTransaction().rollback();

		throw new SQLException(hibernateException);

	} finally {
		session.close();
	}

	return list;
}
 
Example 3
Project: Hibernate_Component_Mapping_Using_DAO_Using_Maven   File: DAO_Impl.java   View Source Code Vote up 6 votes
@Override
public List<Object[]> getdataCondition() {
	List<Object[]> newlist=null;
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
		//access the named query
	Query q=ses.getNamedQuery("select_by_range");
	q.setParameter("salary", 50000f);
		//execute the query
	newlist=q.list();
	newlist.forEach(row->{
		for(Object val:row)
		{
			System.out.println("--->"+val);
		}
		System.out.println();
		
	});
	
	return null;
}
 
Example 4
Project: Hibernate_Component_Mapping_Using_DAO_Using_Maven   File: DAO_Impl.java   View Source Code Vote up 6 votes
public List<person> getdata() {
	List<person> plist=null;
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
	//access the named query
	Query q=ses.getNamedQuery("select_All");
	//execute the QBC logic
	plist=q.list();
	//diaplsy the list
	plist.forEach(p->{
		System.out.println(p);
	});
	
	return null;
}
 
Example 5
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: UserDAOImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
    @Override
	public List<User> findByEmail(String email) {
    	Session session = this.sessionFactory.getCurrentSession();
        TypedQuery<User> query = session.getNamedQuery("findByEmail");  
        query.setParameter("email", email);
//    	Query query = session.getNamedQuery("findByEmail");
//    	query.setString("email", email);
        return query.getResultList();
	}
 
Example 6
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: UserDAOImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public List<User> findByEmailAndPassword(String email, String password) {
	Session session = this.sessionFactory.getCurrentSession();
	TypedQuery<User> query = session.getNamedQuery("findByEmailAndPassword");  
       query.setParameter("email", email); 
       query.setParameter("password", password);
       return query.getResultList();
}
 
Example 7
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public List<Doctor> findBySpecialityCode(String code) {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Doctor> query = session.getNamedQuery("findBySpeciality");  
       query.setParameter("specialityCode", code);
       List<Doctor> doctors = query.getResultList();
       return doctors;
}
 
Example 8
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public Doctor findByUserId(int userId) {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Doctor> query = session.getNamedQuery("findById");  
       query.setParameter("id", userId);
       List<Doctor> doctors = query.getResultList();
       return doctors.get(0);
}
 
Example 9
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public List<Doctor> findAll() {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Doctor> query = session.getNamedQuery("findAll");  
       List<Doctor> doctors = query.getResultList();
       return doctors;
}
 
Example 10
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public int findAllCount() {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Number> query = session.getNamedQuery("findAllCount"); 
       int count = ((Number)query.getSingleResult()).intValue();
       return count;
}
 
Example 11
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: UserDAOImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
    @Override
	public List<User> findByEmail(String email) {
    	Session session = this.sessionFactory.getCurrentSession();
        TypedQuery<User> query = session.getNamedQuery("findByEmail");  
        query.setParameter("email", email);
//    	Query query = session.getNamedQuery("findByEmail");
//    	query.setString("email", email);
        return query.getResultList();
	}
 
Example 12
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: UserDAOImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public List<User> findByEmailAndPassword(String email, String password) {
	Session session = this.sessionFactory.getCurrentSession();
	TypedQuery<User> query = session.getNamedQuery("findByEmailAndPassword");  
       query.setParameter("email", email); 
       query.setParameter("password", password);
       return query.getResultList();
}
 
Example 13
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public List<Doctor> findBySpecialityCode(String code) {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Doctor> query = session.getNamedQuery("findBySpeciality");  
       query.setParameter("specialityCode", code);
       List<Doctor> doctors = query.getResultList();
       return doctors;
}
 
Example 14
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public Doctor findByUserId(int userId) {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Doctor> query = session.getNamedQuery("findById");  
       query.setParameter("id", userId);
       List<Doctor> doctors = query.getResultList();
       return doctors.get(0);
}
 
Example 15
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public List<Doctor> findAll() {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Doctor> query = session.getNamedQuery("findAll");  
       List<Doctor> doctors = query.getResultList();
       return doctors;
}
 
Example 16
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: DoctorDAOImpl.java   View Source Code Vote up 5 votes
@Override
public int findAllCount() {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Number> query = session.getNamedQuery("findAllCount"); 
       int count = ((Number)query.getSingleResult()).intValue();
       return count;
}
 
Example 17
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: RxDAOImpl.java   View Source Code Vote up 5 votes
@Override
public List<Rx> findByDoctorId(int doctorId) {
	Session session = this.sessionFactory.getCurrentSession();
       TypedQuery<Rx> query = session.getNamedQuery("findByDoctorId");  
       query.setParameter("id", doctorId);
       List<Rx> rxList = query.getResultList();
	return rxList;
}
 
Example 18
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: UserDAOImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
    @Override
	public List<User> findByEmail(String email) {
    	Session session = this.sessionFactory.getCurrentSession();
        TypedQuery<User> query = session.getNamedQuery("findByEmail");  
        query.setParameter("email", email);
//    	Query query = session.getNamedQuery("findByEmail");
//    	query.setString("email", email);
        return query.getResultList();
	}
 
Example 19
Project: Building-Web-Apps-with-Spring-5-and-Angular   File: UserDAOImpl.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public List<User> findByEmailAndPassword(String email, String password) {
	Session session = this.sessionFactory.getCurrentSession();
	TypedQuery<User> query = session.getNamedQuery("findByEmailAndPassword");  
       query.setParameter("email", email); 
       query.setParameter("password", password);
       return query.getResultList();
}
 
Example 20
Project: Equella   File: TermDaoImpl.java   View Source Code Vote up 5 votes
private void modifyLeftOrRight(Session session, String queryName, Taxonomy taxonomy, int from, int to, int amount)
{
	Query q = session.getNamedQuery(queryName);
	q.setInteger("amount", amount);
	q.setInteger("from", from);
	q.setInteger("to", to);
	q.setParameter("taxonomy", taxonomy);
	q.executeUpdate();
}