| Adding items to a lazy loading many-to-many Set (and saving the entity) doesn't trigger the appropriate INSERT SQL query, so the new relations are not saved, when the parent entity has an @ElementCollection field too. A self-contained demo is available in HHH-10865.zip , it's runnable with mvn clean test. I've experienced this issue both with Hibernate ORM 5.1.0 and 5.2.0; but 5.0.9 seems to be working fine. I've found that any of the following changes make it work again (see the demo app):
- Uncomment the parent.getNames(); command at Main.java:75.
- Remove the names field, and the getNames() and setNames(Set<String>) methods of the Parent entity.
- Change the fetch attribute of the @ManyToMany annotation to FetchType.EAGER.
- Set enableLazyInitialization to false in pom.xml.
- Change Hibernate's version to 5.0.9 in pom.xml (there are two instances).
Performing any of these changes makes the insert into parents_children (parent, child) values (?, ?) SQL command appear in the standard output. |