gpt4 book ai didi

java - Hibernate 因 HQL 交叉连接而受阻

转载 作者:行者123 更新时间:2023-12-01 14:17:52 25 4
gpt4 key购买 nike

在摆弄下面的代码后,我突然收到一个异常,告诉我“事务未成功启动”。我似乎并没有摆脱它。你能发现 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com