gpt4 book ai didi

java - Hibernate 查询返回等于值的列表

转载 作者:行者123 更新时间:2023-11-29 12:05:28 24 4
gpt4 key购买 nike

我有这个查询:

Query query1 = session.createSQLQuery(
//"select transactions.userId from transactions where transactions.id in (select tickets.transactionId from tickets where tickets.validate=:validate and tickets.auctionId in (select id from auctions where sellShare=:sellShare)) group by transactions.userId")
"select transactions.userId, auctions.id from auctions inner join (tickets inner join transactions on tickets.transactionId = transactions.id) on auctions.id = tickets.auctionId where auctions.sellShare = :sellShare and tickets.validate=:validate")
.addEntity(Test.class).setParameter("sellShare", 1).setParameter("validate", 1);
List<Test> tests = query1.list();

查询返回包含 20 个字段的列表,但它们都是相等的。我该如何修复它?我知道查询工作正常,因为在 mysql 中返回了正确的字段。

enter image description here

这是 Test 的 xml 映射:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="applica.luxury.frontend.viewmodel.Test">
<id name="id" type="long">
<generator class="native" />
</id>
<property name="userId" />
</class>
</hibernate-mapping>

最佳答案

试试这个东西

List<Test> tests = null;
String query = "select transactions.userId, auctions.id from auctions inner join (tickets inner join transactions on tickets.transactionId = transactions.id) on auctions.id = tickets.auctionId where auctions.sellShare = :sellShare and tickets.validate=:validate";
tests = (List<Test>) ((Query) session.createQuery(query).addEntity(Test.class).setParameter("sellShare", 1).setParameter("validate", 1)).list();

迭代测试列表并获取值。希望这能成功。

关于java - Hibernate 查询返回等于值的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31556139/

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