'How to Set parameter to null value in java with hibernate?

I try to get all data in table(SELECT * FROM) mysql database, Using real time search, But not load data to table.

I called getAll("") method with empty String, But I can't get any value from my table.

public ArrayList<Titem> getAll(String text) throws SQLException, ClassNotFoundException {
            Session session = HibernateUtil.openSession();
            Query query = session.createQuery("FROM titem WHERE id = :id");
            query.setParameter("id",text);
            List<Titem> list = query.list();
            ArrayList<Titem> entityList = new ArrayList<>();
            for (Titem t:list
            ) {
                Titem titem = new Titem(
                        t.getId(),
                        t.getName(),
                        t.getPrice()
                );
                entityList.add(titem);
            }
            return entityList;

    }


Solution 1:[1]

You need to conditionally remove the where statement to stop filtering on that column, empty string or null values will also be matched against the data in the table. Or you could change the query to:

FROM titem WHERE (id = :id OR :id = '')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1