Eager Fetch is not stable for collection or map types?

#1

Hi, thanks very much for your helpful software. The problem is the storage of collection or map types is not stable, we lost them sometimes after JVM restarted. Eager fetch is properly set.And we still found that the storage is stable when we not use generic, such as "private List users = new ArrayList();" instead of "private List<User> users = new ArrayList<User>();".

 

The code about entity and fetch is:

@Entity
public class Game {
    .......

    @ElementCollection(fetch=FetchType.EAGER)

    private List<Player> members = new ArrayList<Player>();

    .......
}

@Embeddable
public class Player {
......
}



public class GameDAO {

......

public Game getGame(long id) {
   EntityManager em = emf.createEntityManager();
   try {
    TypedQuery<Game> query = em.createQuery("select k from Game k where k.id=:id", Game.class);
    List<Game> result = query.setParameter("id", id).getResultList();
    if(result.size() > 0) {
      Game g = result.get(0);
      return g;
    }
   } finally {
    em.close();
   }
   return null;
}

......
}

 

#2

Currently there is no known open bug that can cause this problem (including in using or not using generics) so this could also be a bug in the application.

You will have to isolate the problem and if it is not a bug in your application -  please provide a complete test case that demonstrates the problem.

ObjectDB Support
#3

Thanks a lot for your response. We had checked our application, and the additional info is we confirm that the collection or map are stored successfully by using explorer tools when the JVM stopped, but lost when we restart the JVM. Further more, we find if we invoke a mehtod such as size() of collection or map before closing the EntityManager, data can be retrieved successfully: 

 

 public class GameDAO {

......

public Game getGame(long id) {
   EntityManager em = emf.createEntityManager();
   try {
    TypedQuery<Game> query = em.createQuery("select k from Game k where k.id=:id", Game.class);
    List<Game> result = query.setParameter("id", id).getResultList();
    if(result.size() > 0) {
      Game g = result.get(0);

      logger.debug("[trace_fetch] ["+g.getMembers().size()+"]");

      return g;
    }
   } finally {
    em.close();
   }
   return null;
}

......
}
#4

OK. So the data is not lost (since you can reach it) but not eagerly retrieved.

Which ObjectDB version are you using? If not the last (2.3.3_07) - please try the last.

If it is an ObjectDB bug - please provide a test case, as explained in the posting instructions and it will be fixed.

ObjectDB Support

Reply