Notes: 1. the User with userId = 1 has a row in the USER_ROLE association table, and the query works. The user with userId = 2 has no row in the USER_ROLE association table, and the query throws java.lang.NullPointerException. 2. In the User.java entity bean, if I change the FetchMode for the roles collection from @Fetch(FetchMode.SUBSELECT)to @Fetch(FetchMode.JOIN), both queries work. |