[Edit: Apparently, this is only a problem for arrays, and FoxyBOA's answer may direct (or even have) the answer.]
My question is about this software: Hibernate3 + Annotation, Spring MVC, MySQL, and in this example also Spring Security.
I was wondering why collections that are automatically linked to Hibernate contain null values for each row number of the child table (in addition to the correct elements). My example:
I have a table of users and permissions, the primary key of the user table is the username that is used as a foreign key. Right now, 13 rows in the table of my authorities. When I retrieve the user from the database (MySQL InnoDB), and Hibernate automatically receives user privileges corresponding to this mapping:
@OneToMany
@JoinColumn(name = "username")
@IndexColumn(name="id")
public Authority[] getAuthorities() {
return authorities;
}
public void setAuthorities(Authority[] authorities) {
this.authorities = authorities;
}
... I get a collection of "permissions" containing 14 (0-13) elements, of which only four are non-zero (four rows in the database table belong to this particular user, so that’s right). As far as I understand, I use the default values for Hibernate for properties like Fetchmode, etc. I get the user as follows:
Criteria criteria = getSession().createCriteria(User.class);
criteria.add(Restrictions.eq("username",username));
User user = (User) criteria.uniqueResult();
org.hibernate.loader.loader "" . , . :
java.lang.IllegalArgumentException: Granted authority element 0 is null - GrantedAuthority[] cannot contain any null elements