作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在摆弄下面的代码后,我突然收到一个异常,告诉我“事务未成功启动”。我似乎并没有摆脱它。你能发现 Java 方法中的错误吗?
数据模型
建议:suggestion_id、name、isReceivedNSD、isSetupNSD、isDecidedUHR、meeting_id、..
session :meeting_id,日期
日志:log_id、suggestion_id、..
这里的特别之处在于:
控制面板:controlpanel_id、processMeeting_id(始终只有一行,包含当前选择)
Java方法
public static List<Suggestion> getSuggestion(final int maxResults,
final boolean isReceivedNSD, final boolean isSetupNSD, final boolean isDecidedUHR,
final Status status) throws GettingException {
final Transaction transaction = getSession().getTransaction();
List<Suggestion> list = null;
final Query query;
try {
final String hql = "select f" //
+ " from Controlpanel p, Log L" //
+ " where L.suggestion.isReceivedNSD = :isReceivedNSD" //
+ " and L.suggestion.isSetupNSD = :isSetupNSD" //
+ " and L.suggestion.isDecidedUHR = :isDecidedUHR" //
+ " and L.status.id = :statusId" //
+ " and L.suggestion.meeting.id = p.processMeeting.id";
query = getSession().createQuery(hql);
query.setParameter("isReceivedNSD", isReceivedNSD);
query.setParameter("isSetupNSD", isSetupNSD);
query.setParameter("isDecidedUHR", isDecidedUHR);
query.setParameter("statusId", status.getId());
query.setMaxResults(maxResults);
list = castList(Suggestion.class, query.list());
transaction.commit();
}
catch (final HibernateException e) {
throw new GettingException("Suggestion list. " + e.getMessage());
}
finally {
HibernateCommon.rollbackIfNeededDuringHenting(transaction);
}
return list;
}
最佳答案
消息很明确:交易未成功启动。您忘记开始交易:
final Transaction transaction = getSession().getTransaction();
transaction.begin();
或者简单地说:
final Transaction transaction = getSession().beginTransaction();
关于java - Hibernate 因 HQL 交叉连接而受阻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17943467/
我是一名优秀的程序员,十分优秀!