开发者社区 问答 正文

如何通过Criteria查询数量呢(需要指定条件)

JAVA 框架-Hibernate-查询 这样一个多对一,但我现在需要查询指定sectionId的数据的数量,设定topic_sectionId为条件在运行时会提示找不到could not resolve property: topic_sectionId of: com.tonglee.bean.TopicBean 我是需要在bean中再添加sectionId这个参数吗?

展开
收起
YDYK 2021-01-25 15:00:09 2960 分享 版权
1 条回答
写回答
取消 提交回答
  • 上面的问题我通过传入相应对象是可以解决的,但依然无法查询到结果。 通过百度我看到有让设置cascade="all"或者save-update,persist;然而并没有成功。 并且我现在是查询而网上大多数查到的是插入。 关键代码: List list = s.createCriteria(TopicBean.class).add(Restrictions.eq("section", SectionGet.getSection(0))).list(); SectionGet.getSection(0):SectionBean section = (SectionBean)s.get(SectionBean.class, id); 报错: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing

    2021-01-25 15:00:36
    赞同 展开评论
问答分类:
问答地址: