Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Bugs/256277"
m (→Bug Analysis Document: 256277: Endless loop on @PrePersist using a nested Persist) |
m (→Bug Analysis Document: 256277: Endless loop on @PrePersist using a nested Persist) |
||
Line 20: | Line 20: | ||
This bug is encountered when a secondary persist is executed inside of a @PrePersist callback method on the Entity being itself persisted. | This bug is encountered when a secondary persist is executed inside of a @PrePersist callback method on the Entity being itself persisted. | ||
+ | There are two use cases here, one when the secondary entity persist contains its own @PrePersist callback with a persist - causing an infinite loop, the second use case is when the secondary entity persisted does not do a persist in it's own @PrePersist. | ||
== Concepts == | == Concepts == | ||
Line 59: | Line 60: | ||
− | ===Use Case 1: Persist other Entity (with its own @PrePersist) inside @PrePersist callback === | + | ===Use Case 1: Persist other Entity (with its own @PrePersist and persist) inside @PrePersist callback === |
+ | This use case currently causes an infinite loop on the following line up to build 20090105. | ||
+ | <source lang="java"> | ||
+ | EntityClassListener(EntityListener).prePersist(DescriptorEvent) line: 412 | ||
+ | </source> | ||
+ | ===Use Case 2: Persist other Entity (with its own @PrePersist with a persist) inside @PrePersist callback === | ||
+ | Normal functionality with no infinite loop. | ||
− | ===Use Case | + | ===Use Case 3: Persist other Entity (without its own @PrePersist) inside @PrePersist=== |
+ | Normal functionality with no infinite loop. | ||
== Analysis Constraints == | == Analysis Constraints == |
Revision as of 16:19, 5 January 2009
Contents
- 1 Bug Analysis Document: 256277: Endless loop on @PrePersist using a nested Persist
- 1.1 Document History
- 1.2 Overview
- 1.3 Concepts
- 1.4 Reproduction
- 1.4.1 Prerequisites
- 1.4.2 Use Case 1: Persist other Entity (with its own @PrePersist and persist) inside @PrePersist callback
- 1.4.3 Use Case 2: Persist other Entity (with its own @PrePersist with a persist) inside @PrePersist callback
- 1.4.4 Use Case 3: Persist other Entity (without its own @PrePersist) inside @PrePersist
- 1.5 Analysis Constraints
- 1.6 Design / Functionality
- 1.7 Testing
- 1.8 API
- 1.9 GUI
- 1.10 Config files
- 1.11 Documentation
- 1.12 Open Issues
- 1.13 Decisions
- 1.14 Future Considerations
- 1.15 References
Bug Analysis Document: 256277: Endless loop on @PrePersist using a nested Persist
Document History
Date | Author | Version Description & Notes |
---|---|---|
20080105 | Michael O'Brien | 1.0 Initial reproduction use cases |
Overview
This bug is encountered when a secondary persist is executed inside of a @PrePersist callback method on the Entity being itself persisted. There are two use cases here, one when the secondary entity persist contains its own @PrePersist callback with a persist - causing an infinite loop, the second use case is when the secondary entity persisted does not do a persist in it's own @PrePersist.
Concepts
JPA Specification Notes
Here is what the JPA specification says about performing persists inside the @PrePersist method. Essentially it states that we should not be performing persists inside a @PrePersist callback - however it is the responsibility of the container to handle any that may be done.
JPA 1.0 Specification
- P58 Section 3.5
- "In general, portable applications should not invoke EntityManager or Query operations, access other entity instances, or modify relationships in a lifecycle callback method.[19]"
- "[19] The semantics of such operations may be standardized in a future release of this specification."
JPA 2.0 Specification
- P82 Section 3.5.1
- "In general, portable applications should not invoke EntityManager or Query operations, access other entity instances, or modify relationships within the same persistence context.[34] A lifecycle callback method may modify the non-relationship state of the entity on which it is invoked."
- "[34] The semantics of such operations may be standardized in a future release of this specification."
Reproduction
Prerequisites
- Run tests out of container on an SE persitence unit
- At least two entities must be persisted to avoid performance optimization code for a single entity
- Two different entity classes are required
- Test must commit more than one object so that the non-performance else clause in CommitManager.commitAllObjectsWithChangeSet() is used
- Test must perform a change on an existing object that is already persisted
- Set FlushMode
- entityManager.setFlushMode(FlushModeType.AUTO);
- Set @PrePersist method callback on Entity that performs its own read query
@Entity public class Leaf implements Serializable { @PrePersist // 256277: test prePersist public void prePersist() { setState("0000"); }
Use Case 1: Persist other Entity (with its own @PrePersist and persist) inside @PrePersist callback
This use case currently causes an infinite loop on the following line up to build 20090105.
EntityClassListener(EntityListener).prePersist(DescriptorEvent) line: 412
Use Case 2: Persist other Entity (with its own @PrePersist with a persist) inside @PrePersist callback
Normal functionality with no infinite loop.
Use Case 3: Persist other Entity (without its own @PrePersist) inside @PrePersist
Normal functionality with no infinite loop.
Analysis Constraints
Design / Functionality
Testing
Use Case 1: Output
The following logs and stacktrace illustrate the current infinite loop behavior when performing a @PrePersist inside a @PrePersist as a result of a persist in this callback method.
StackTrace
Logs
API
GUI
Config files
Documentation
Open Issues
Issue # | Owner | Description / Notes |
---|---|---|
I1 | mobrien | Verify that Entity containing the @PrePersist callback has been registered |
Decisions
Issue # | Description / Notes | Decision |
---|---|---|
Future Considerations
During the research for this bug, the following items were identified as out of scope but are captured here as potential future enhancements. If agreed upon during the review process these should be logged in the bug system.