关于在Hibernate5.3.1中HQL语句使用"?"参数占位符运行报错的问题

在Hibernate5.3.1中,HQL语句使用"?"参数占位符运行报错:

Caused by: org.hibernate.QueryException:

Legacy-style query parameters (`?`) are no longer supported; use JPA-style ordinal parameters (e.g., `?1`) instead

并且:在Query查询时:setInteger()等方法已过时:



解决办法:

1.将HQL语句中的"?"改为JPA-style:

String hql = "from Student where age > ?0 and score < ?1";

2.方法过时问题解决:使用setParameter():

List<Student> list = createQuery .setParameter(0, 21) .setParameter(1, 95.0) .list();

3.使用别名方式写HQL语句:

String hql = "from Student where age > :myage and score < :myscore";


总结:3种方式对应CODE:


// 1:将HQL语句中的"?"改为JPA-style:
String hql = "from Student where age > ?0 and score < ?1";	
			Query createQuery = session.createQuery(hql);
			List<Student> list = createQuery
					        .setInteger(0, 21)
						.setDouble(1, 95)
						.list();

// 2:使用setParameter():
String hql = "from Student where age > ?0 and score < ?1";    
            Query createQuery = session.createQuery(hql);
            List<Student> list = createQuery
                    .setParameter(0, 21)
                    .setParameter(1, 95.0)
                    .list();

// 3:别名:要求必须以冒号开头:
            String hql = "from Student where age > :myage and score < :myscore";   
            Query createQuery = session.createQuery(hql);
            List<Student> list = createQuery
                    .setInteger("myage", 21)
                    .setDouble("myscore", 95)
                    .list();


  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 Windows 系统上使用 Arduino Bluetooth Plugin 5.3.1 的教程: 1. 下载并安装 Unity 软件,并在 Unity 的 Asset Store 搜索并下载 Arduino Bluetooth Plugin。 2. 打开 Unity 软件,创建一个新的项目,并在项目导入 Arduino Bluetooth Plugin。 3. 确保你的电脑上已经安装了 Arduino IDE 软件,如果没有请前往官网下载并安装。 4. 连接你的 Arduino 蓝牙模块到电脑,并使用 Arduino IDE 软件将以下代码上传到模块: ``` #include <SoftwareSerial.h> SoftwareSerial bluetooth(10, 11); // RX, TX void setup() { Serial.begin(9600); bluetooth.begin(9600); } void loop() { if (bluetooth.available()) { Serial.write(bluetooth.read()); } if (Serial.available()) { bluetooth.write(Serial.read()); } } ``` 5. 打开 Unity 软件的 Arduino Bluetooth Plugin,将以下代码添加到你的 Unity 脚本: ``` using System; using UnityEngine; using System.Collections; using System.IO.Ports; public class BluetoothController : MonoBehaviour { SerialPort stream = new SerialPort("COM3", 9600); // 定义一个串口对象 void Start () { stream.Open(); } void Update () { if (stream.IsOpen) { try { string value = stream.ReadLine(); Debug.Log("Received Data: " + value); } catch (System.Exception) { } } } void OnApplicationQuit() { stream.Close(); } } ``` 6. 将脚本挂载到你的 Unity 场景的任意一个物体上,并运行你的项目。 7. 点击 Unity 编辑器的 Play 按钮,通过蓝牙发送一些数据到 Arduino 上,你应该可以在 Unity 编辑器的 Console 窗口看到接收到的数据。 以上就是在 Windows 系统上使用 Arduino Bluetooth Plugin 5.3.1 的教程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值