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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:36:59+00:00 2026-05-19T09:36:59+00:00

I have two classes, call them Monkey and Banana, with a one-to-many bidirectional relationship.

  • 0

I have two classes, call them Monkey and Banana, with a one-to-many bidirectional relationship.

Monkey monkey = new Monkey();
Banana banana = new Banana();
monkey.Bananas.Add(banana);
banana.Monkey = monkey;
hibernateService.Save(banana);

When I run that chunk of code, I want both monkey and banana to be persisted. However, it’s only persisting both when I explicitly save the monkey and not vice versa. Initially, this made sense since only my Monkey.hbm.xml had a mapping with cascade="all".

<set name="Bananas" inverse="true" cascade="all">
  <key column="Id"/>
  <one-to-many class="Banana"/>
</set>

I figured I just needed to add the following to my Banana.hbm.xml file:

<many-to-one name="Monkey" column="Id" cascade="all" />

Unfortunately, this resulted in a Parameter index is out of range error when I tried to run the snippet of code. I investigated this error and found this post, but I still don’t see what I’m doing wrong. I have the relationship mapped once on each side as far as I can tell. For full disclosure, here are the two mapping files:

Monkey.hbm.xml

<class name="Monkey" table="monkies" lazy="true">
    <id name="Id">
      <generator class="increment" />
    </id>
    <property name="Name" />
    <set name="Bananas" inverse="true" cascade="all">
      <key column="Id"/>
      <one-to-many class="Banana"/>
    </set>
</class>

Banana.hbm.xml

<class name="Banana" table="bananas" lazy="true">
    <id name="Id">
      <generator class="increment" />
    </id>
    <property name="Name" />
    <many-to-one name="Monkey" column="Id" cascade="all" />
</class>
  • 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-19T09:37:00+00:00Added an answer on May 19, 2026 at 9:37 am

    The Parameter index is out of range error is due to your mappings. You have Id mapped as both the primary and foreign keys in the relationships.

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

Sidebar

Related Questions

I have two classes that I am testing (let's call them ClassA and ClassB).
I have two classes (let's call them A and B ), both inheriting from
I have two classes, call them A and B. They both contain a Loader
Is it possible in C++ to have two classes, let's call them A and
Okay, so I have two classes, call them A and B--in that order in
I have two classes, let's call them parent and child, and both need to
I have two abstract classes, lets call them Car 's and Wheel 's. I
I have two classes (let's call them Working and ReturnStatement) which I can't modify,
I have two classes one of which inherits from the other. Im trying to
I have two MXML component files and try to work with them as classes.

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.