OgmEntityPersister / EntityAssociationUpdater is throwing an exception: OGM000082: The entity at the inverse side of the association cannot be found in the session for the use case below, using Redis with the default IN_ENTITY Association Storage. The referenced entities in the exception are absolutely in the session. In my application, this exception seems to be isolated to entities with self-referencing parent-child relationships.
Category Entity {code:java}
@Id private String id; private String name; private byte sortOrder;
@ManyToOne private Category parentCategory; @OneToMany(mappedBy = "parentCategory", fetch = FetchType.EAGER) @OrderBy("sortOrder") private SortedSet<Category> subcategories;
public int compareTo(Category category) { int result = Byte.compare(sortOrder, category.sortOrder); return result != 0 ? result : name.compareTo(category.name); } {code}
EJB Method {code:java} public void reorderSubcategories(Category category) { Category persistedCategory = entityManager.find(Category.class, category.getId()); List<Category> subcategories = new ArrayList<>(category.getSubcategories()); for (Category subcategory : persistedCategory.getSubcategories()) { subcategory.setSortOrder((byte) subcategories.indexOf(subcategory)); } } {code}
A specific example of the exception message is: OGM000082: The entity at the inverse side of the association 'subcategories' cannot be found in the session: EntityKey(Category) [id=4b4c7205-c893-43ec-96a2-34c8d1f87cd6]
In this case, the entity with id=4b4c7205-c893-43ec-96a2-34c8d1f87cd6 is the Category passed to the EJB method and parentCategory to all subcategories. |
|