You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Pawel Veselov <pa...@gmail.com> on 2012/01/22 10:52:00 UTC

@OneToMany on abstract requires explicit @MapKey

Hi.

I ran into this recently, took me a while before I figured it out.

I have a @OneToMany that points to an abstract entity, and is a Map<Long,
Entity>. The entity has Long ID as its primary key. However, OpenJPA
apparently is not mapping the key to the primary ID. The tables are managed
by the JPA, and I would see columns of KEY0, KEY1, etc., each time the
database was refreshed, OpenJPA would add yet another column.

This manifested by me seeing only one entity in the map, no matter how many
I would create (and I created them with reverse mapping). Finally, I
realized that the key value was always (null), so it was finding the
entities by relationship, but since key was mapped to a auto-generated
column that nobody would ever populate, all of them collapsed into one in
the map.

Adding explicit @MapKey to point to the primary key solved this problem.

This is 2.1.1

Thank you,
  Pawel.