Example usage for org.hibernate Session createQuery

List of usage examples for org.hibernate Session createQuery

Introduction

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

Prototype

@Override
    org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);

Source Link

Usage

From source file:backend.api.Statistics.java

public List<FinanceRegister> getFinanceRegisterRecords() // ok
{
    Session s = sf.openSession();
    try {/* w ww  .  j  ava  2  s.  c  om*/

        Query q = s.createQuery("select f from FinanceRegister f");
        List<FinanceRegister> result = q.list();
        if (result.isEmpty() || result.size() == 0)
            return null;
        return result;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public Products getProduct(int idProduct, String type) // po id // nie ma po typie, jezeli chcie to dodam
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from   w  w w.ja v a  2s . c  o m

        Query q = s.createQuery("select p from Products p where '" + idProduct + "'=p.idProducts");
        List<Products> result = q.list();
        if (result.isEmpty() || result.size() == 0)
            return null;
        return (Products) result.get(0);

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public List<Products> getProducts() //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/*from   w w  w .  j ava 2  s.  c o m*/

        Query query = s.createQuery("select p from Products p");

        List<Products> prod = query.list();
        return prod;

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public List<Category> getCategory() //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {// w ww  .  ja va2s.c om

        Query query = s
                .createQuery("select new backend.core.model.Category(c.idCategory, c.name) from Category c");

        List<Category> category = query.list();
        return category;

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public Category getCategory(int idCategory) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from w w w .ja  v a 2 s . c  om

        Query query = s.createQuery("from Category c where c.idCategory='" + idCategory + "'");

        List<Category> category = query.list();
        if (category.isEmpty() || category.size() == 0)
            return null;
        return (Category) category.get(0);

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public Category getCategory(String name) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/* ww  w  . java 2s .  c o m*/

        Query query = s.createQuery("from Category c where c.name='" + name + "'");

        List<Category> category = query.list();
        if (category.isEmpty() || category.size() == 0)
            return null;
        return (Category) category.get(0);

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public List<Manufacturers> getManufacturer() //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from   w  w w  .jav  a2s.co  m

        Query query = s.createQuery("select m from Manufacturers m");

        List<Manufacturers> manu = query.list();
        return manu;

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public Manufacturers getManufacturer(String name) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {//from   w w  w.j a  v  a  2  s.com

        Query query = s.createQuery("select m from Manufacturers m where m.name= '" + name + "'");

        List<Manufacturers> manu = query.list();
        if (manu.isEmpty() || manu.size() == 0)
            return null;
        return (Manufacturers) manu.get(0);

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public Manufacturers getManufacturer(int idManufacturer) //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/*from   w  ww. jav  a2 s .co  m*/

        Query query = s
                .createQuery("select m from Manufacturers m where m.idManufacturer= '" + idManufacturer + "'");

        List<Manufacturers> manu = query.list();
        if (manu.isEmpty() || manu.size() == 0)
            return null;
        return (Manufacturers) manu.get(0);

    } finally {
        s.close();
    }
}

From source file:backend.api.StorageManagement.java

public List<Attributes> getAttributes() //ok
{
    Session s = SessionFactoryManager.INSTANCE.getSessionFactory().openSession();
    try {/*from w w  w .  ja v a  2 s  . c o m*/

        Query query = s.createQuery("select a from Attributes a");

        List<Attributes> attributes = query.list();
        return attributes;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        s.close();
    }
}