I have two classes in an m:n relationship, defined as:
My reading of the docs is that these connections will be automatically created by the bit-twiddling under the covers. So that when an Item is added to the items attribute of Layer, a corisponding relationship should be created from Item.layers back to the Layer the Item was added to. But this is not happening. The following test fails:Code:public class Item { @RelatedTo(type="MEMBERS", direction = Direction.INCOMING) Set<Layer> layers; } public class Layer { @RelatedTo(type="MEMBERS") Set<Item> items; }
Am I not understanding something? Or is this a bug?Code:@Test @Transactional public void testTwoWayRelationshipCounts(){ Layer layer1 = repository.save(new Layer()); Layer layer2 = repository.save(new Layer()); Item item1 = template.save(new Item()); layer1.addItem(item1); layer2.addItem(item1); repository.save(layer1); repository.save(layer2); template.save(item1); assertEquals(1, layer1.items.size()); assertEquals(1, layer2.items.size()); assertEquals(2, item1.layers.size()); // fails, as it is 0 }
Thanks.


Reply With Quote