apache / apache/grails-core

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

Open
#14,455 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-hibernate5
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### 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

Contributor guide

Open the contributing guide

Research direction

Start by running the example application linked in the issue and reproduce the behavior at /test/index and /test/index2, focusing on post.removeFromLocations(location). Compare the observed collection fetch with the GORM 6.1 documentation section 5.4.3; done means removing an item from the bag does not fetch the entire collection.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.