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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:49:47+00:00 2026-05-11T03:49:47+00:00

I have two entities, Entity1 and Entity2, on a one to many relationship. On

  • 0

I have two entities, Entity1 and Entity2, on a one to many relationship. On Entity1 I have a map which contains entries.

The code I use to persist a new Entity1 with some Entity2 on the map is like this:

   Entity1 e1 = new Entity1();      Entity2 e2 = null;      e1.setE2s(new HashMap<String, Entity2>());    for (String key : someKeySet()){       e2 = new Entity2();       e2.setCode(key);                             e2.setSwhon(true);               e2.setE1(e1);       e1.getE2s(key, e2);              em.persist(e1.getE2s().get(key));               }            em.persist(e1);     em.flush(); 

and here is a exctract of the entities:

@Entity @Table(name = 'wm_Entities1')   public class Entity1 implements Serializable {      private static final long serialVersionUID = 6592708276573465599L;      private Map<String, Entity2> e2s;    private Long id;      @Id      @GeneratedValue(strategy=GenerationType.TABLE)      public long getId() {       return id;      }      public void setId(long id) {       this.id = id;      }      public void setE2s(Map<String, Entity2> e2s){         this.e2s = e2s;    }           @OneToMany(mappedBy = 'e1', fetch = FetchType.EAGER)      public Map<String, Entity2> getE2s() {       return e2s;      }   } 

@Entity @Table(name = 'wm_Entities2') public class Entity2 implements Serializable {       private static final long serialVersionUID = -6131765066573346790L;      private long id;     private Entity1 e1;     @Id     @GeneratedValue(strategy=GenerationType.TABLE)     public long getId() {         return id;     }      public void setId(long id) {         this.id = id;     }     @ManyToOne()     @JoinColumn(name='e1_id')     public Entity1 getE1() {         return this.e1;     }     public void setE1(Entity1 e1) {         this.e1 = e1;     } } 

This seems to work fine since it inserts both entities on the pg database, but the catch is that it is not creating-saving the MapKey of the e2 on the database (theoretically JPA generates this key), so when I get the e1 back, and I try to get the e2s map from it, I have a:

javax.ejb.EJBException: org.hibernate.HibernateException: null index column for collection:

How can I get this MapKey saved??

Note: I’m using JavaEE with JPA/Hibernate, running over JBoss 4.2, with PGSQL DB.

  • 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. 2026-05-11T03:49:47+00:00Added an answer on May 11, 2026 at 3:49 am

    There are some oddities in your code… But it seems that you should add a @MapKey annotation in Entity1:

    (snippet) @OneToMany(mappedBy = 'e1', fetch = FetchType.EAGER) @MapKey(name='iCantFigureTheRightPropertyName') public Map<String, Entity2> getE2s() {       return e2s;   }   
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is situation I have: I have two entities with one-to-many relationship mapped like
I have two entities, a User and Role with a one-to-many relationship from user
i have two entities named Parent and Child , linked in a one-to-many relationship.
I have a data model which has two entities in a relationship of one
I have two entities Foo and Bar with a Many to Many relationship between
i have two Entities, Parent and Child, that are linked through a bidirectional one-to-many
i have two entities one called User and another called Membership which has a
I have two Entity Framework objects with a one-to-many relationship: widget(parent) and widgetNail(child) Widget
I've got two entities with a one-to-many relationship between them. The entity that holds
I have entities Post and Tag , where there is a many-to-many relationship between

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.