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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 236k
  • Answers 236k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You ask: at what point does the flexibility and cost… May 13, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer If you want to do any more complex date manipulation,… May 13, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer <script type="text/javascript"> var ViewData_a = "<%= ViewData["a"] %>"; </script> ...… May 13, 2026 at 6:25 am

Related Questions

[Edit: Apparently, this is only an issue for arrays and FoxyBOA's answer might direct
Okay this is a real headscratcher. I have an application which calls a web
I have a problem with an ASP.NET application that is driving me nuts. When
A few weeks ago I wrote an SNMP relayer for our ops group. They
I'm building a toy database in C# to learn more about compiler, optimizer, and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.