hibernate的获取返回值的问题

上去就一个404 2017-11-07 09:04:24

public Long getCompanyIdByUser(Long id) {
Session session = sessionFactory.getCurrentSession();
Query q = session.createQuery("select companyId from USER where id=?id");
Long Companyid = (Long)q.uniqueResult();
return Companyid;
}




我这样写获取不到我想要的查询结果,请问应该怎么写呢
...全文
175 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
j_boss2222 2017-11-07
  • 打赏
  • 举报
回复
Query q = session.createQuery("select companyId from USER u where u. id=" + id);
上去就一个404 2017-11-07
  • 打赏
  • 举报
回复
erloude
引用 2 楼 yuxiangaaaaa 的回复:
[quote=引用 1 楼 yuxiangaaaaa 的回复:] Query q = session.createQuery("select companyId from USER where id=?id"); Query q = session.createQuery("select companyId from USER where id=?" + id);
Query q = session.createQuery("select companyId from USER where id=" + id);[/quote] 这个不行
自由自在_Yu 2017-11-07
  • 打赏
  • 举报
回复
引用 1 楼 yuxiangaaaaa 的回复:
Query q = session.createQuery("select companyId from USER where id=?id"); Query q = session.createQuery("select companyId from USER where id=?" + id);
Query q = session.createQuery("select companyId from USER where id=" + id);
自由自在_Yu 2017-11-07
  • 打赏
  • 举报
回复
Query q = session.createQuery("select companyId from USER where id=?id"); Query q = session.createQuery("select companyId from USER where id=?" + id);

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧