Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 220127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:54:34+00:00 2026-05-11T18:54:34+00:00

[Edit: Apparently, this is only an issue for arrays and FoxyBOA’s answer might direct

  • 0

[Edit: Apparently, this is only an issue for arrays and FoxyBOA’s answer might direct to (or even is) the answer.]

My question relates to these software: Hibernate3+Annotation, Spring MVC, MySQL and in this example also Spring Security.

I was wondering, why collections, which are automatically associated by Hibernate contain null values for each row number of the child table (besides the elements which are correct). My Example:

I have a users and an authorities table, the primary key of the users table is username which serves as foreign key. Right now, there are 13 rows in my authorities table. When I retrieve a user from the database (MySQL InnoDB) and Hibernate automatically retrieves the user’s authorities corresponding to this mapping:

@OneToMany
@JoinColumn(name = "username")
@IndexColumn(name="id") // "id" was the primary key and is used to sort the elements
public Authority[] getAuthorities() {
    return authorities;
}
public void setAuthorities(Authority[] authorities) {
    this.authorities = authorities;
}

… I end up with a collection “authorities” containing 14 (0-13) elements of which only four are not-null (four rows in the database table belong to that specific user, so that is correct). As far as I realize, I am using Hibernate defaults for properties like Fetchmode etc. I am getting the user like this:

Criteria criteria = getSession().createCriteria(User.class);
criteria.add(Restrictions.eq("username",username));
User user = (User) criteria.uniqueResult();

The logging information from org.hibernate.loader.loader correctly “mentions” four rows for the resultset. Still, the user created has the four correct elements plus ten null values in the Array. In my specific example, this results in this exception:

java.lang.IllegalArgumentException: Granted authority element 0 is null - GrantedAuthority[] cannot contain any null elements
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:54:34+00:00Added an answer on May 11, 2026 at 6:54 pm

    I can recommend you check your data. If you have a missed indexes (id column in your case), then instead of missed id you’ll get null in your array.
    I.e.

    table authorities:
    username id
    bob 1
    bob 3
    bob 5
    

    As a result you will have an array:
    {0=null, 1=bob, 2=null, 3=bob, 4=null, 5=bob}

    UPDATE:
    I met the situation in two cases:

    1. Missed key values in indexed column id at authorities table (e.g. 0,1,3,4,5 – missing value 2. Hibernate will automatically add to an array value with key 2 and value null).
    2. Indexed values are in order, but select criteria filter part of them (e.g. your HQL similar to that “from user u join u.authorities a where a.id=2”. In that case hibernate load a user, but in authorities array you will have only 3 values: 0 – null, 1 – null, 2 – authority with id 2).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit : This question has already been asked and answered, and I apparently am
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Sorry, this is my first time using this forum. Apparently people can edit my
EDIT : It turned out that this can only be done through an external
This might be a stupid question, but I notice that in a good number
Edit: derp, using pageX/Y instead of clientX/Y -- apparently scrollBy expects input with that
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
Edit : Note that, as Daniel and latkin noted in an answer and a
In this question I am looking for links/code to handle an IList<OrderLine> in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.