We're updating the issue view to help you get more done. 

Put entities with database generated IDs in the second-level cache on insert

Description

Consider an entity with the following annotations on the ID property and a valid second-level cache configuration. Such an entity is not found in the second-level cache right after session.saveOrUpdate(entity)

1 2 @javax.persistence.Id @javax.persistence.GeneratedValue(strategy = GenerationType.IDENTITY)

The following commented out code snippet in EntityIdentityInsertAction.execute() indicates that caching of newly inserted entities in the second-level cache is currently not supported. The according entity only shows up in the second-level cache after loading from the database.

1 2 3 4 5 6 7 //TODO: this bit actually has to be called after all cascades! // but since identity insert is called *synchronously*, // instead of asynchronously as other actions, it isn't /*if ( persister.hasCache() && !persister.isCacheInvalidationRequired() ) { cacheEntry = new CacheEntry(object, persister, session); persister.getCache().insert(generatedId, cacheEntry); }*/

Also entities with database generated IDs should be put in the second-level cache right after insertion in the database.

Environment

None

Status

Assignee

Unassigned

Reporter

tscho

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.1.9
4.2.0.CR1

Priority

Major