gorm-hibernate5 icon indicating copy to clipboard operation
gorm-hibernate5 copied to clipboard

removing from a collection mapped as a bag triggers a fetch of the whole collection

Open bp-FLN opened this issue 6 years ago • 0 comments

Task List

  • [x] Steps to reproduce provided
  • [ ] Stacktrace (if present) provided
  • [x] Example that reproduces the problem uploaded to Github
  • [x] Full description of the issue provided (see below)

Steps to Reproduce

  1. run the Example Application
  2. navigate to http://localhost:8080/test/index to trigger the issue for many-to-many
  3. navigate to http://localhost:8080/test/index2 to trigger the issue for one-to-many

Expected Behaviour

as per documentation, it is not expected that the whole collection is being fetched see section 5.4.3 here: http://gorm.grails.org/6.1.x/hibernate/manual/#sets "...adding to or removing from collections mapped as a Bag don’t trigger a load of all existing instances from the database..."

Actual Behaviour

The whole locations collection is fetched when calling post.removeFromLocations(location), which is very costly if there are thousand of items in the database.

Environment Information

  • Operating System: MacOS
  • GORM Version: 6.1.11.RELEASE
  • Grails Version (if using Grails): 3.3.9
  • JDK Version: jdk1.8.0_121

Example Application

  • https://github.com/bp-FLN/gorm-removeFromBag-issue

bp-FLN avatar Feb 12 '19 22:02 bp-FLN