Search code examples
hibernatecriteria

Hibernate criteria : the origin class


I was wondering if there was a way to get the name of the class that was used to create the criteria.

Example :

Criteria c = session.createCriteria(MyClasse.class)

So I would like to know, when I have the criteria c, that MyClasse was used to make it

thank you


Solution

  • You can get the Criteria's Entity or ClassName by,

     Criteria c = sessionFactory.getCurrentSession().createCriteria(Customer.class);
    ((CriteriaImpl) c).getEntityOrClassName() - would give you Customer
    
    • Maddy