Hello,
I have User entity class with this mapping:
Code:
@CollectionOfElements
@JoinTable(name = "User_roles", joinColumns = @JoinColumn(name = "User_id"))
private Set<String> roles = new HashSet<String>();
The generated table looks like this:
Code:
CREATE TABLE `User_roles` (
`User_id` bigint(20) NOT NULL,
`element` varchar(255) default NULL,
KEY `FKEA147569555F3082` (`User_id`)
)
I want to select all Users having one or more specific roles. For that, I defined a NamedQuery like this:
Code:
@NamedQuery(
name = "User.findByRole",
query = "SELECT user FROM User user WHERE user.roles IN (:roles)"
)
I then have this method in my service bean:
Code:
public List<User> findByRole(String ... roles) {
Query q = getEntityManager().createNamedQuery("User.findByRole");
q.setParameter("roles", roles);
return q.getResultList();
}
I then get the following error message from Mysql driver:
JDBCExceptionReporter.logExceptions - SQL Error: 0, SQLState: 07001
JDBCExceptionReporter.logExceptions - No value specified for parameter 1
If you take a look below, the generated query is missing even the reference to the element column.
I have the Persistence with Hibernate book, but I just don't see what I'm doing wrong here.
Can anybody help me here? It seems that what I want to accomplish is rather straight forward, isn't it?
Hibernate version: Hibernate 3.2.4.sp1, EM 3.3.1, Annot 3.3.0
Name and version of the database you are using:MySQL 5.0.38-Ubuntu_0ubuntu1-log
The generated SQL (show_sql=true):Code:
select
user0_.id as id7_,
user0_.email_id as email10_7_,
user0_.login as login7_,
user0_.password as password7_,
from
User user0_,
User_roles roles1_
where
user0_.id=roles1_.User_id
and (
. in (
?
)
)