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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:40:29+00:00 2026-05-29T19:40:29+00:00

I have a Person class mapped to a PERSON table, and an Address class

  • 0

I have a Person class mapped to a PERSON table, and an Address class mapped to an ADDRESS table. What I want is for each Person to have two lists of Addresses: homeAddresses and officeAddresses. The ADDRESS table has one foreign-key field, PERSONID, for both cases, but it has two separate list-index fields: a home_add_idx for records belonging in homeAddresses, and an off_add_idx for records belonging in officeAddresses. For any given ADDRESS record, one of these list-index fields will be NULL. This all works perfectly on insert, but when I try to retrieve records, I get an exception, “null index column for collection”. (Full stacktrace below.)

How can I do this?

Person.java:

public class Person implements Serializable {
    private String personId;
    private String personName;
    private List<Address> homeAddresses = new ArrayList<Address>();
    private List<Address> officeAddresses = new ArrayList<Address>();

    public String getPersonId() { return personId; }
    public void setPersonId(String s) { personId = s; }
    public String getPersonName() { return personName; }
    public void setPersonName(String s) { personName = s; }
    public List<Address> getHomeAddresses() { return homeAddresses; }
    public void setHomeAddresses(List<Address> L) { homeAddresses = L; }
    public List<Address> getOfficeAddresses() { return officeAddresses; }
    public void setOfficeAddresses(List<Address> L) { officeAddresses = L; }
}

Address.java:

public class Address implements Serializable {
    private String id;
    private String houseNo;
    // [SNIP - street, city, country]
    private String postalCode;

    public String getId() { return id; }
    public void setId(String s) { id = s; }
    public String getHouseNo() { return houseNo; }
    public void setHouseNo(String s) { houseNo = s; }
    // [SNIP - getters for street, city, country]
    public String getPostalCode() { return postalCode; }
    public void setPostalCode(String s) { postalCode = s; }
}

Person.hbm.xml:

<hibernate-mapping>
<class name="com.nadhi.list.test.Person" table="PERSON">
    <id name="personId" type="java.lang.String">
        <column name="PERSONID" />
        <generator class="assigned" />
    </id>
    <property name="personName" type="java.lang.String">
        <column name="PERSONNAME" />
    </property>
    <list name="homeAddresses" inverse="false" table="ADDRESS" lazy="false" cascade="all">
        <key>
            <column name="PERSONID"/>
        </key>
       <list-index column="home_add_idx"></list-index>
        <one-to-many class="com.nadhi.list.test.Address" />
    </list>
    <list name="officeAddresses" inverse="false" table="ADDRESS" lazy="false" cascade="all">
        <key>
            <column name="PERSONID"/>
        </key>
       <list-index column="off_add_idx"></list-index>
        <one-to-many class="com.nadhi.list.test.Address" />
    </list>
</class>
</hibernate-mapping>

Address.hbm.xml:

<hibernate-mapping>
<class name="com.nadhi.list.test.Address" table="ADDRESS">
    <id name="id" type="java.lang.String">
        <column name="ID" />
        <generator class="assigned" />
    </id>
    <property name="houseNo" type="java.lang.String">
        <column name="HOUSENO" />
    </property>
    <!-- [SNIP - mappings for street, city, country] -->
    <property name="postalCode" type="java.lang.String">
        <column name="POSTALCODE" />
    </property>
</class>
</hibernate-mapping>

When I insert data, I insert a separate home and office address for the same Person. It inserts correctly. However, when I try to retrieve the Person object, I get the following exception:

org.hibernate.HibernateException: null index column for collection: com.nadhi.list.test.Person.officeAddresses
at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:770)
at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:402)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1156)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:774)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:622)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2166)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:62)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:627)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1863)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:479)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:900)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:279)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:369)
at com.nadhi.list.test.Main.getPerson(Main.java:113)
at com.nadhi.list.test.Main.main(Main.java:36)

In the database, I can see that for home address, the office address column index is empty; and for office address, the home address column index is empty. But isn’t that expected? What do I need to do in order to retrieve the data correctly?

  • 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-29T19:40:32+00:00Added an answer on May 29, 2026 at 7:40 pm

    I think you need to replace the ADDRESS.PERSONID foreign-key field with two separate foreign-key fields — one for home addresses, one for office addresses.

    The list-index fields, you can leave as they are, or you can merge them into a single field, or you can remove them entirely and use a <bag> instead of a <list> mapping. (Obviously that last approach is only good if you don’t care about the order of addresses within the list; I don’t know whether you do.)

    When you think about it — it makes sense that the list-index column doesn’t accomplish what you want. That column is only used for lists (not sets and bags), so it would not be a very general-purpose way to indicate which collection a record belongs to. So it makes sense that it’s only used to specify the list-index for a record that’s already been determined to belong to the right collection.

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

Sidebar

Related Questions

I have a Person class with two properties: name and address . I want
I have two tables called Person and Address . These tables I mapped one
I have this class mapped as a entity, lets call it Person. Person has
I have a Person class which has a String collection of aliases representing additional
I have a class Person and a class Name. Name contains two Strings firstName
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
Say I have two domain objects and a mapper interface. class Person { int
I have a Person class (annotated with @XmlRootElement ) in Java with two properties
I have a Person class that I save to a table in Azure Table
I have two models: Company and Person class Person < ActiveRecord::Base belongs_to :company end

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.