我想从用户加入的数据库中提取所有事件。
DAO:
public List<Event> getUserJoinedEvents(User user) {
return sessionFactory.getCurrentSession()
.createQuery("FROM Event event WHERE event.eventMembersJoined = :user")
.setParameter("user", user).list();
实体:
...
@JoinTable(name="MEMBERS_JOINED_EVENT",
joinColumns={@JoinColumn(name="JOINED_EVENT_ID")},
inverseJoinColumns={@JoinColumn(name="USER_ID")})
private Set<User> eventMembersJoined = new HashSet<User>();
...
结果异常:
java.sql.SQLException: No value specified for parameter 1
我错过了什么?
答案 0 :(得分:2)
eventMembersJoined
是Set
,但是您使用=
将其与User
类型的参数进行比较。
要查看天气集合包含某些元素,请尝试使用:
FROM Event event WHERE :user in elements(event.eventMembersJoined)