我正在将遗留代码升级到Hibernate 6。我收到了用于更新查询的RESTQuery方法的弃用警告。如何修复此代码?Google搜索只给出了旧API的示例。
public static int setLastIpTimeStamp(Timestamp ipLastTimeStamp)
{
int rowsaffected = -1;
try (Session session = SessionFactoryManager.getSessionFactory().openSession())
{
Transaction tx = session.beginTransaction();
try
{
Query query = session.createQuery("UPDATE HistoryDataProcessorSettingsEntity row SET row.ipLastTimeStamp=:ipLastTimeStamp WHERE row.id=:id ")
.setParameter("id", 1)
.setParameter("ipLastTimeStamp", ipLastTimeStamp.toInstant());
rowsaffected = query.executeUpdate();
tx.commit();
}
catch (Exception e)
{
tx.rollback();
if (Logger.isErrorEnabled())
Logger.error(e);
}
}
catch (Exception e)
{
if (Logger.isErrorEnabled())
Logger.error(e);
}
return rowsaffected;
}
1条答案
按热度按时间uyhoqukh1#
根据最新的javadoc,你应该使用
createMutationQuery()
,因为你只做更新: