gpt4 book ai didi

java - 检查实体是否在映射实体列表中

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:17:06 24 4
gpt4 key购买 nike

我有以下 Hibernate 代码,我认为它应该可以工作,但它会引发错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: ERROR: syntax error at or near "." Position: 503

相关代码如下:

@Override
public List<RepositoryLink> getRepositoryLinks(final DugaUser user) {
Query query = sessionFactory.getCurrentSession()
.createQuery("from RepositoryLink link where :user in (link.dugaUsers)");
query.setParameter("user", user);
return query.list();
}

其中 RepositoryLink 如下:

@Entity
@Table(name = "repository_links")
public class RepositoryLink {
@Id
@GeneratedValue
private Integer id;

@OneToOne
@JoinTable(name = "repository_links_github_repositories",
joinColumns = {@JoinColumn(name = "github_repository_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "repository_link_id", referencedColumnName = "id")})
private GithubRepository githubRepository;

@OneToMany
@JoinTable(name = "repository_links_duga_users",
joinColumns = {@JoinColumn(name = "duga_user_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "repository_link_id", referencedColumnName = "id")})
private List<DugaUser> dugaUsers = new ArrayList<>();

public Integer getId() {
return id;
}

public GithubRepository getGithubRepository() {
return githubRepository;
}

public void setGithubRepository(final GithubRepository githubRepository) {
this.githubRepository = githubRepository;
}

public List<DugaUser> getDugaUsers() {
return dugaUsers;
}

public void setDugaUsers(final List<DugaUser> dugaUsers) {
this.dugaUsers = dugaUsers;
}
}

我可能可以让它与一些连接一起工作,但我认为如果我可以让 in 语法工作会更好,为什么它不能像这样工作?

最佳答案

如果不亲自检查 hibernate 文档,我无法再直接详细说明为什么这有效。 ;)

在您的查询中使用它:IN elements(link.dugaUsers)

关于java - 检查实体是否在映射实体列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29681270/

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