gpt4 book ai didi

java - 如何访问多选条件元组查询中的连接列?

转载 作者:行者123 更新时间:2023-11-29 18:02:29 26 4
gpt4 key购买 nike

表类:

private static final long serialVersionUID = 1L;
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@JoinColumn(name = "SUBSYSTEM_ID", referencedColumnName = "ID")
@ManyToOne
private Subsystem subsystem;

@Transient
private Long subsystemId;

和标准查询:

public PagedSearchResult<Tuple> findByUserId1(Long id, UserSubsystemSearchCriteria searchCriteria) {
final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
final CriteriaQuery<Tuple> query = criteriaBuilder.createTupleQuery();
final Root<UserSubsystem> from = query.from(UserSubsystem.class);
query.multiselect(from.get("subsystemId"));
query.groupBy(from.get("subsystemId"));

如果我删除联接并瞬时重写列定义,它可以工作,但我需要该联接。

最佳答案

不知道你想要实现什么,但最简单的解决方案

@Entity
class UserSubsystem {

private static final long serialVersionUID = 1L;

@Id
private Long id;

@JoinColumn(name = "SUBSYSTEM_ID", referencedColumnName = "ID")
@ManyToOne
private Subsystem subsystem;

@Column(name = "SUBSYSTEM_ID", updatable = false, insertable = false)
private Long subsystemId;

}

并查询

CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<UserSubsystem> query = criteriaBuilder.createQuery(UserSubsystem.class);
Root<UserSubsystem> from = query.from(UserSubsystem.class);
from.fetch("subsystem", JoinType.LEFT);
query.groupBy(from.get("subsystemId"));
entityManager.createQuery(query);

关于java - 如何访问多选条件元组查询中的连接列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48216529/

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