apache / apache/grails-core

GORM withStatelessSession does not appear to create a stateless session

Open
#14,614 1 comment 1 reaction 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

I'm attempting to use GORM's withStatelessSession and finding that either it doesn't work, or I'm completely misunderstanding the concept.

The attached project has an integration test (StatelessSessionTest) that uses withStatelessSession to wrap a block of code. Within this block, there is an entity loaded into the PersistenceContext from outside the block, and a GORM finder returns this entity from the cache.

AbstractDatastore.createStatelessSession simply delegates to createSession, and HibernateDatastore doesn't seem to override this anywhere in its inheritance tree.

### Task List

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

### Steps to Reproduce

1. Run StatelessSessionTest, observe the failure
2. Uncomment the GORM finder, breakpoint at SessionImpl#601
3. The entity is returned from the PersistenceContext cache

### Expected Behaviour

The entity should be loaded without using cached state.

### Actual Behaviour

The entity is returned using cached state.

### Environment Information

- **Operating System**: Windows 10
- **GORM Version:** 6.1.2
- **Grails Version (if using Grails):** 3.2.8
- **JDK Version:** 1.8.0_121

### Example Application
[test-stateless.zip](https://github.com/grails/grails-data-mapping/files/977667/test-stateless.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached reproduction and run StatelessSessionTest to confirm the failure. Read AbstractDatastore.createStatelessSession and the HibernateDatastore inheritance tree, then inspect the SessionImpl#601 path described in the issue. Done means withStatelessSession loads the entity without returning cached state, while the reproduction test passes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.