openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pawel Veselov <>
Subject @OneToMany on abstract requires explicit @MapKey
Date Sun, 22 Jan 2012 09:52:00 GMT

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,

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message