Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Problem with loading of data with a OneToMany relationship

Hello Christian,

First off, when you create the Entry entities and associate a Group to them, are you also adding them to the Group's list of entries?  JPA does not maintain bidirectional relations for you; the application must set both sides of all relationships or they can become inconsistent with what is in the database.  If this is the case, you can either correct the application, or issue a refresh (via em.refresh() or EclipseLink queryhint) on Group which will cause it to fetch the Entry entities associated in the database.

Best Regards,
Chris

On 04/06/2010 8:41 AM, Christian (VuuRWerK) Seifert wrote:
Hi,

I've got a problem with my OneToMany relationship. The depending data won't be loaded. Here a shorted listing of my coding:
================= SNIP =================
public class Group {
  private String name;

  @OneToMany(mappedBy = "group", fetch = FetchType.EAGER)
  private List<Entry> entries = new ArrayList<Entry>();
  // ... getter/setter
}

public class Entry {
  @ManyToOne
  @JoinColumn(name = "FK_GROUP_ID")
  private Group group;
  // ... getter/setter
}
================= SNAP =================

I try to fetch the data using the JpaEntityManager (the jpaEm var) and ExpressionBuilder (the builder var):
================= SNIP =================
Query qry = jpaEm.createQuery(builder.get("name").equal(builder.getParameter("searchName")), Group.class);
qry.setParameter("searchName", name);
Object result = qry.getSingleResult();
================= SNAP =================

So the "result" is a valid instance of Group but the list of entries are empty, although there are 3 entries with the correct group-id in the database. There is no other errors by eclipselink or anything else.
Hope someone can help me and I'm very glad about some suggestions. Thanks in advance.

Regards
Christian


_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Back to the top