我有一个使用 Hibernate HQL 查询的类。我想将这些更改为 Hibernate Criteria 查询。然而,Hibernate Criteria 对我来说比 HQL 更难理解,即使有教程也是如此。有人可以告诉我其中一个查询如何使用 Hibernate Criteria/Filters 吗?
Configuration configuration = new Configuration();
configuration.configure().setProperty("hibernate.show_sql", "false");
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
configuration.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(serviceRegistry);
Session session =sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Query query = session.createQuery("from TABLENAME WHERE IDObject1= :idObjectA" +
"AND IDObject2= :idObjectB AND IDSettingOption = :idSettingOption");
query.setParameter("idObjectA", idObjectB);
query.setParameter("idObjectB", idObjectB);
query.setParameter("idSettingOption", idSettingOption);
List results = query.list();
提前致谢!