Check if Entity is in the list of displayed objects

I have the following Hibernate code that I think should work, but it throws an error:

org.springframework.web.util.NestedServletException: request processing failed; The nested exception is org.hibernate.exception.SQLGrammarException: ERROR: syntax error at or near the point. Position: 503

The corresponding code is as follows:

@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(); } 

Where is RepositoryLink following:

 @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; } } 

I could make it work with some unions, but I thought it would be better if I could make the in syntax work, why doesn't it work like that?

+6
source share
1 answer

I can no longer explain in detail why this works without checking the dormant documents themselves.;)

Use this in your query: IN elements(link.dugaUsers)

+5
source

Source: https://habr.com/ru/post/985288/


All Articles