I have the following Hibernate code which I believe should be working, but it throws an error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: ERROR: syntax error at or near "." Position: 503
The relevant code is the following:
@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 RepositoryLink
is the 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 probably get it working with some joins, but I thought it would be nicer if I could get the in
syntax to work, why doesn't it work like this?
I cannot elaborate directly anymore why this works, without checking the hibernate docs myself. ;)
Use this in your query: IN elements(link.dugaUsers)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With