Я хочу получить данные из 3 таблиц в ассоциации 1: * с таблицей соединений между ними, показанной ниже -
Таблица ProductCategory ==> J Таблица ProductCategory_Product ==> Таблица Product ==> J Таблица Product_ProdSpec ==> Таблица ProdSpec
Теперь я хочу получить запись на основе спецификации продукта и показать ее в таблице HTML.
Я использовал запрос Критерии гибернации для этого следующим образом:
Session session = HibernateUtil.getSessionFactory().openSession();
Criteria offerCriteria = session.createCriteria(ProductCategory.class)
.createAlias("productList","productList")
.createAlias("productList.prodSpecList","prodSpecList")
.add(Restrictions.like("prodSpecList.prodSpecDesc", "%dual Sim%"))
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
List list = offerCriteria.list();
Hibernate создает следующие запросы -
Hibernate: select this_.productCategoryNumber as productC1_0_2_, this_.ProductCategoryType as ProductC2_0_2_, productlis4_.productCategoryNumber as productC1_0_, productlis1_.productNumber as productN2_, productlis1_.productNumber as productN1_1_0_, productlis1_.productCompanyName as productC2_1_0_, prodspecli6_.productNumber as productN1_1_, prodspecli2_.prodSpecNumber as prodSpec2_, prodspecli2_.prodSpecNumber as prodSpec1_2_1_, prodspecli2_.prodSpecDesc as prodSpec2_2_1_ from ProductCategory this_ inner join ProductCategory_Product productlis4_ on this_.productCategoryNumber=productlis4_.productCategoryNumber inner join Product productlis1_ on productlis4_.productNumber=productlis1_.productNumber inner join Product_ProdSpec prodspecli6_ on productlis1_.productNumber=prodspecli6_.productNumber inner join ProdSpec prodspecli2_ on prodspecli6_.prodSpecNumber=prodspecli2_.prodSpecNumber where prodspecli2_.prodSpecDesc like ?
Hibernate: select productlis0_.productCategoryNumber as productC1_0_1_, productlis0_.productNumber as productN2_1_, product1_.productNumber as productN1_1_0_, product1_.productCompanyName as productC2_1_0_ from ProductCategory_Product productlis0_ inner join Product product1_ on productlis0_.productNumber=product1_.productNumber where productlis0_.productCategoryNumber=?
Hibernate: select prodspecli0_.productNumber as productN1_1_1_, prodspecli0_.prodSpecNumber as prodSpec2_1_, prodspec1_.prodSpecNumber as prodSpec1_2_0_, prodspec1_.prodSpecDesc as prodSpec2_2_0_ from Product_ProdSpec prodspecli0_ inner join ProdSpec prodspec1_ on prodspecli0_.prodSpecNumber=prodspec1_.prodSpecNumber where prodspecli0_.productNumber=?
Hibernate: select prodspecli0_.productNumber as productN1_1_1_, prodspecli0_.prodSpecNumber as prodSpec2_1_, prodspec1_.prodSpecNumber as prodSpec1_2_0_, prodspec1_.prodSpecDesc as prodSpec2_2_0_ from Product_ProdSpec prodspecli0_ inner join ProdSpec prodspec1_ on prodspecli0_.prodSpecNumber=prodspec1_.prodSpecNumber where prodspecli0_.productNumber=?
Hibernate: select prodspecli0_.productNumber as productN1_1_1_, prodspecli0_.prodSpecNumber as prodSpec2_1_, prodspec1_.prodSpecNumber as prodSpec1_2_0_, prodspec1_.prodSpecDesc as prodSpec2_2_0_ from Product_ProdSpec prodspecli0_ inner join ProdSpec prodspec1_ on prodspecli0_.prodSpecNumber=prodspec1_.prodSpecNumber where prodspecli0_.productNumber=?
и возвращает следующий результат.
productCategoryType :- Mobile[productCompanyName :- Samsung prodSpecList :- [GPS navigation, music (MP3), video (MP4) playback, dual Sim, video calling, built-in cameras, games, office, Bluetooth, WiFi, instant messaging, Internet, e-mail, browsing], productCompanyName :- LG prodSpecList :- [GPS navigation, video (MP4) playback, video calling, games, Bluetooth, instant messaging, e-mail], productCompanyName :- Sony prodSpecList :- [music (MP3), dual Sim, built-in cameras, office, WiFi, Internet, browsing]]
У меня есть следующие вопросы:
- Почему он создает слишком много запросов, так как достаточно только 1-го запроса
и хорошо?
- Почему он возвращает все данные? Все ли запросы запускаются в данных
база
- Пожалуйста, дайте мне пример кода для использования?