Issue #618: Eager Fetch of Map with Entities as Keys

Type: Bug ReoprtVersion: 2.3.4Priority: NormalStatus: ActiveReplies: 0

Loading eagerly a map that uses entity objects as keys is currently unsupported, if the equals and hashCode methods of the keys are based on the key entity persistent content, since that content is unavailable during instantiation of the map.

The following test case demonstrates the problem:

import java.util.*;
import javax.persistence.*;

public class T618 {

    public static void main(String[] args) {

        EntityManagerFactory emf =

        EntityManager em = emf.createEntityManager();
        MyEntity entity = new MyEntity();
        MyKeyEntity key = new MyKeyEntity("key");
        em.persist(key);, "value");

        em = emf.createEntityManager();
        entity = em.find(MyEntity.class, 1);


    public static class MyEntity {
        @Id private long id = 1;
        Map map = new HashMap();
    public static class MyKeyEntity {
        private String name;
        MyKeyEntity(String name) {
   = name;
        public boolean equals(Object obj) {
            return name.equals(((MyKeyEntity)obj).name);
        public int hashCode() {
            return name.hashCode();

Running the test results in a NullPointerException during map instantiation:

at T618$MyKeyEntity.hashCode(
at java.util.HashMap.put(
at Source)
at com.objectdb.o.MPT.I(
at com.objectdb.o.TYT.extractMap(
at com.objectdb.o.ENT.extractMap(
at Source)
at Source)
at com.objectdb.o.MFT.a(
at com.objectdb.o.LDR.C(
at com.objectdb.o.LDR.F(
at com.objectdb.o.LDR.Vs(
at com.objectdb.o.FTP.d(
at com.objectdb.o.PFT.a(
at com.objectdb.o.LDR.C(
at com.objectdb.o.LDR.y(
at com.objectdb.o.LDR.x(
at com.objectdb.o.LDR.UU(
at com.objectdb.o.MST.aT(
at com.objectdb.o.MST.aS(
at com.objectdb.o.MST.U1(
at com.objectdb.o.WRA.U1(
at com.objectdb.o.LDR.w(
at com.objectdb.o.LDR.v(
at com.objectdb.o.LDR.s(
at com.objectdb.o.OBC.aM(
at com.objectdb.o.OBC.aK(
at com.objectdb.jpa.EMImpl.find(
at com.objectdb.jpa.EMImpl.find(
at T618.main(


ObjectDB Support