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 6761825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:14:16+00:00 2026-05-26T14:14:16+00:00

There is a Java SE project with Hibernate ORM. I feel that the problem

  • 0

There is a Java SE project with Hibernate ORM. I feel that the problem is trivial, but need some help.

There is a code snippet:

    SessionFactory factory = new Configuration().configure().buildSessionFactory();

    Session s = factory.openSession();

    int id = 1;

    ExperimentSetResult experimentSetResult = (ExperimentSetResult)s.get(ExperimentSetResult.class, id);

    System.out.println("size: " + experimentSetResult.getExperimentResults().size());
    System.out.println("id[0]: " + experimentSetResult.getExperimentResults().get(0).getId());

I get a NullPointerException for the last string of code (when accessing the 0-th element of a collection associated with an object loaded recently).

There are the hbm files snippets:

ExperimentResult.hbm.xml:

<hibernate-mapping>
    <class name="rmocommon.driverreaction.ExperimentResult" table="experiment_results">
        <id name="id" type="int">
            <generator class="increment"/>
        </id>
        <many-to-one class="rmocommon.driverreaction.ExperimentSetResult" name="ExperimentSetResult" column="ExperimentSetResultId" not-null="true" />
    </class>
</hibernate-mapping>

ExperimentSetResult.hbm.xml:

<hibernate-mapping>
    <class name="rmocommon.driverreaction.ExperimentSetResult" table="experiment_set_results">
        <id name="id" type="int">
            <generator class="increment"/>
        </id>

        <list name="ExperimentResults" cascade="all-delete-orphan" inverse="true">
            <key column="ExperimentSetResultId" not-null="true"/>
            <list-index column="Id"/>
            <one-to-many class="rmocommon.driverreaction.ExperimentResult"/>
        </list>    
    </class>
</hibernate-mapping>

What’s wrong with mapping or with my source code?

UPDATE:
Here is an output and a stack trace:

Hibernate: select experiment0_.id as id4_2_, experiment0_.StartedDate as StartedD2_4_2_, experiment0_.FinishedDate as Finished3_4_2_, experiment0_.DeviceOutput as DeviceOu4_4_2_, person1_.id as id0_0_, person1_.Login as Login0_0_, person1_.LastName as LastName0_0_, person1_.Patronymic as Patronymic0_0_, person1_.FirstName as FirstName0_0_, person1_.Age as Age0_0_, experiment2_.id as id1_1_, experiment2_.TestMode as TestMode1_1_, experiment2_.TransportType as Transpor3_1_1_, experiment2_.TransportStartSpeed as Transpor4_1_1_, experiment2_.RoadType as RoadType1_1_, experiment2_.RoadLength as RoadLength1_1_, experiment2_.DirectionLeft as Directio7_1_1_, experiment2_.RespondToFirstEffort as RespondT8_1_1_, experiment2_.SoundOnFirstEffort as SoundOnF9_1_1_, experiment2_.ScaleObjects as ScaleOb10_1_1_, experiment2_.ShowTransportSpeed as ShowTra11_1_1_, experiment2_.BarrierXMin as Barrier12_1_1_, experiment2_.BarrierXMax as Barrier13_1_1_, experiment2_.ReactionTime as Reactio14_1_1_, experiment2_.SoundOnBarrierAppearance as SoundOn15_1_1_, experiment2_.AllowedCheatCount as Allowed16_1_1_ from experiment_set_results experiment0_ left outer join persons person1_ on experiment0_.id=person1_.id left outer join experiment_set_settings experiment2_ on experiment0_.id=experiment2_.id where experiment0_.id=?
Hibernate: select experiment0_.ExperimentSetResultId as Experim11_4_1_, experiment0_.id as id1_, experiment0_.Id as Id1_, experiment0_.id as id2_0_, experiment0_.Distance as Distance2_0_, experiment0_.Crash as Crash2_0_, experiment0_.BrakingStarted as BrakingS4_2_0_, experiment0_.BrakingStartedTime as BrakingS5_2_0_, experiment0_.BrakingStartedDistance as BrakingS6_2_0_, experiment0_.BarrierX as BarrierX2_0_, experiment0_.Number as Number2_0_, experiment0_.Time as Time2_0_, experiment0_.Valid as Valid2_0_, experiment0_.ExperimentSetResultId as Experim11_2_0_ from experiment_results experiment0_ where experiment0_.ExperimentSetResultId=?
size: 6
Exception in thread "main" java.lang.NullPointerException
    at hibernateTest.HibernateTest.main(HibernateTest.java:45)
Java Result: 1
  • 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-26T14:14:17+00:00Added an answer on May 26, 2026 at 2:14 pm

    Might be that your mapping is wrong. Your list-index column definetly should not be ID.
    If you really need the ordering, you better create a separate column for that, otherwise you will encounter problems.

    Another thing I’ve noticed. You don’t have to specify the inverse on the one-to-many relationship.

    It’s been a while I’ve seen hbm.xml files, can you use annotations? They are much easier to understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's a Java library that I would like to use in my project. My
I'm working on a java project full of Hibernate (3.3.1) mapping files that have
I am working on a JAVA project in which there are multiple terminals. These
Is there any other implementation (e.g. in an OSS project) of a Java SecurityManager
Is there any Java library that supports hierarchical column? For example (the first three
I am using maven2 with a struts-hibernate Java EE project and developing with myEclipse.
I'm a contributor to a Java Open Source project which integrates with Hibernate. I'm
Is there any tutorial or a book that shows how to create a Java
Are there any tools that auto-generate the hibernate POJOs by gathering information from the
Totally new to Spring & Java development but working on a project for a

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.