unexpected char: '@' [from cn.mani123.domain.Order where product = cn.mani123.domain.Product@11d48a7

本文解决了一个关于使用HibernateTemplate进行HQL查询时遇到的错误,该错误涉及到对象哈希值的不当使用。当使用外键关联时,直接传递对象到HQL语句会导致查询失败,文章提供了正确的做法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用hibernate template查询时报错

unexpected char: '@' [from cn.mani123.domain.Order where product = cn.mani123.domain.Product@11d48a78 and account = cn.mani123.domain.Account@647a4fc8 and status = 5]; nested exception is org.hibernate.QueryException: unexpected char: '@' [from cn.mani123.domain.Order where product = cn.mani123.domain


原因:数据库中表使用外键,直接通过hql语句查询时查询的是哈希值,需要查找的hql有对象时,须使用

List<Order> list = this.getHibernateTemplate().find(hql,product,account);

product和account均为对象查询!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值