【发布时间】:2015-06-17 04:30:51
【问题描述】:
我有一个如下所示的 HQL。当我运行这个 HQL 时,我得到了错误。我想使用一个对象列表作为参数。我想使用这个对象属性。我已经通过使用 Criteria 和 DetachedCriteria 解决了这个问题,但我想知道 HQL 中是否有任何解决方案。
<named-query name="Book.findBooksByPropertyValue">
<query>
select book
from Book book
join book.bundleProperty bundleProperty
join bundleProperty.property property
left join bundleProperty.selectedProperty selectedProperty
where
property.code in :bundleProperty.property.code and
(bundleProperty.propertyValue in :bundleProperty.propertyValue or selectedProperty.id in :bundleProperty.selectedProperty.id)
</query>
</named-query>
class Book()
{
//...
BundleProperty bundleProperty;
}
class BundleProperty()
{
...
boolean propertySelective;
Property property;
String propertyValue;
PropertyChoice selectedProperty;
}
class bookController()
{
//...
public List<Book> findBooks()
{
List<BundleProperty> bundleProperties = new ArrayList<>();
for(PropertyBase propertyBase : selectedPropertyBases )
{
BundleProperty bundleProperty = new BundleProperty();
bundleProperty.setProperty(propertyBase.getProperty());
if(propertyBase.getProperty().isPropertySelective())
{
bundleProperty.setSelectedProperty(propertyBase.getSelectedProperty());
}
else
{
bundleProperty.setPropertyValue(propertyBase.getPropertyValue());
}
bundleProperties.add(bundleProperty);
}
return bookService.findBooksByPropertyValue(bundleProperties);
}
}
class bookServiceImp()
{
//...
public List<Book> findBooksByPropertyValue(List<BundleProperty> bundleProperties)
{
return getSession().getNamedQuery("Book.findBooksByPropertyValue")
.setParameterList("bundleProperty", bundleProperties)
.list();
}
}
【问题讨论】:
标签: hibernate hql named-query