【发布时间】:2012-04-17 00:39:09
【问题描述】:
这是我的问题:
我有这门课它很少有@oneToMany 集合
public class ActivePropertyList implements Serializable
{
@OneToMany
@JoinTable(name = "PropertyAttributeLink",
joinColumns =
@JoinColumn(name = "EANHotelID"),
inverseJoinColumns =
@JoinColumn(name = "AttributeID", referencedColumnName="AttributeID"))
private Collection<AttributeList> attributeList;
@OneToMany(fetch= FetchType.LAZY)
@JoinColumn(name="EANHotelID")
private Collection<Hotelimageslist> hotelimageslist;
@OneToMany(fetch= FetchType.LAZY)
@JoinColumn(name="EANHotelID")
private Collection<Roomtypelist> roomtypelist;
//Getters & Setters ...
当我从 XHTML 访问这个对象时,生成时间太长,因为我使用 <ui:repeat value=#{controller.ActivePropertyList.attributeList}> ...
PropertyAttributeLink 有超过 500 万行,图像有超过 400 万行,但是当我使用简单的 SQL 查询 innerJoin 时,生成列表的时间不超过几毫秒。
我尝试使用 HQL 查询在 AttributeList 上使用 namedQuery,但由于 AttributeList 没有引用 ActivePropertyList,因为它是单向的@oneToMany,这样做会引发错误。
有没有办法创建 HQL NamedQuery 来访问每个列表一次并将其存储在控制器中?
类似
public List<AttributeList> getAttributeListByHotelID(int hotelID){
Query q = session().createQuery("from AttributeList AL inner join PropertyAttributeLink PA where PA.hotelID=:hotelID");
return q.list();
}
但是这个方法不起作用,因为 hql 需要 AttributeList 来了解 PropertyAttributeLink
【问题讨论】:
标签: java hibernate jakarta-ee jsf-2