gpt4 book ai didi

java - Hibernate 不检索所需的记录

转载 作者:行者123 更新时间:2023-12-02 06:41:06 26 4
gpt4 key购买 nike

我无法从数据库中检索所需的记录,我的类如下,我需要知道哪些用户有不活动的购物篮。

Class Person {

}

Class User extends Person{
private Set<Basket> basketlist;
}

Class Prof extends User {

}

Class Basket{
private String active;
}


Criteria cre = session.createCriteria(User.class, "user")
.createAlias("user.basketlist", "basket");
ProjectionList pl = Projections.projectionList();
pl.add(Projections.property("user.id").as("id"));
cre.setProjection(pl);
cre.add(Restrictions.eq("basket.active", null));
IDs = cre.list();

上面的代码生成以下查询(我不确定为什么它在此查询中包含 Prof,以及为什么它不显示具有非 Activity 购物篮的用户)

select this_.id as y0_ from User this_ inner join Person this_1_ on 
this_.id=this_1_.id left outer join Prof this_2_ on this_.id=this_2_.id inner join
User_basketlist basketl3_ on this_.id=basketl3_.User_id inner join basketlist
basketl1_ on basketl3_.basketlist_id=basketl1_.id where basketl1_.active=?

我的 Hibernate 版本

 <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.1.Final</version>
<type>jar</type>
</dependency>

最佳答案

对于 NULL 应该是

Restrictions.isNull("basket.active")

关于java - Hibernate 不检索所需的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19128923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com