【发布时间】:2009-10-28 11:53:37
【问题描述】:
我有以下 bean Task、ServerDetails 和 ApplicationDetails。 我希望根据特定的应用程序名称检索所有任务、它们的服务器详细信息和应用程序详细信息。
从结果中,我希望能够以如下方式检索数据: task.getServers().getApplicationDetails()
实际上,我将平面数据表示为 Object[]。
有什么办法可以按照我的建议去做吗?
以下是我的代码...
class Task {
private String taskId;
private Set<ServerDetails> servers;
}
class ServerDetails {
private String id;
private Set<ApplicationDetails> applications;
}
class ApplicationDetails {
private String id;
}
HQL:
StringBuilder hql = new StringBuilder(256);
hql.append("FROM Task h, ServerDetails ser, ApplicationDetails app ");
hql.append("WHERE h.executionDate > ");
hql.append("to_date('");
hql.append(DBDateFormatter.getInstance().formatDate(cal));
hql.append("', '");
hql.append(DBDateFormatter.getInstance().getOracleDateFormat());
hql.append("') and h.id = ser.task.id and ser.id = app.server and app.name = 'XXX'");
hql.append(" order by h.executionDate desc");
String hql = hql.toString();
Query query = session.createQuery(hql);
results = (List<Object[]>) query.list();
【问题讨论】: