声明-在HQL休眠中设置

问题描述

如何在HQL Hibernate中声明变量?与sql一样吗?

这是我的代码,我需要迁移到休眠状态:

DECLARE @variable int
SET @variable = (SELECT variable from entity WHERE description LIKE ('%small%')) 
SELECT...

解决方法

解决方案很简单。您无法在HQLhibernate)中声明和设置变量,因此必须在Java中复制对象,然后再创建一个repository(Java类)来解析{{ 1}}和DECLARE子句。

恢复:从SET到Java(存储库)做同样的事情,并连接变量

,

我解决了这个问题。我只是在 CONTROLLER 中声明一个对象并保存它。 例子:

//create an new object of the Entity and save using JPA
Example example = new Example() ;
example.setFuncion();
ExampleRepository.save(example);
//done