-
Notifications
You must be signed in to change notification settings - Fork 192
Description
Product/Component: EclipseLink JPA
Observed Behavior (The Bug): A JPA entity using property access for a boolean field experiences a failure in assignment when the setter method's parameter is named identically to the conventional getter method name. Although the setter is called successfully (e.g., in a @PrePersist listener) with a value of true, the class field remains false after the assignment line. This indicates a potential conflict or malfunction during the framework's introspection of the method signature.
Expected Behavior: The simple Java assignment within the setter (this.bool = isBool;) should execute successfully regardless of the parameter name, provided the parameter does not shadow the field name (which is the case here). The class field should be correctly updated.
To Reproduce
- EclipseLink version: 4.0.1
- Java/JDK version: 17
- Create a simple Jakarta EE project with EclipseLink as the JPA provider.
- Define an entity (e.g., MyEntity) with a boolean field (bool) and standard accessors.
- Name the boolean getter method isBool().
- Name the boolean setter method's parameter isBool.
- Call the setter via a listener (e.g., @PrePersist) or directly with a value of true.
- Observe the field value after assignment (e.g., via logging or debugger).
@Entity
public class MyEntity {
@Id
private Long id;
private boolean bool;
// Getter: Naming convention is 'isBool()'
public boolean isBool() { return bool; }
// Setter: Parameter name 'isBool' matches getter name
public void setBool(boolean isBool) {
System.out.println("Param Value: " + isBool); // Prints: true
this.bool = isBool; // <-- Assignment Fails!
System.out.println("Field Value: " + this.bool); // Prints: false
}
}
Workaround
The issue is resolved by simply changing the setter method's parameter name to anything other than the getter's name prefix (e.g., setBool(boolean value)).