@LifeCycleHookBinding doesn't work with ENUM
Expected Behavior
@LifeCycleHookBinding should work with ENUM fieldCurrent Behavior
@LifeCycleHookBinding doesn't work with ENUM fieldPossible Solution
Steps to Reproduce (for bugs)
- Create Entity with Enum field
- Use @LifeCycleHookBinding for this field example ( @LifeCycleHookBinding(operation = UPDATE, phase = PRECOMMIT, hook = YourHook.class) StateEnum state' )
- Try to change entity using json API
- Hook will not work =(
Context
Your Environment
- Elide version used: 7.0.1
- Java 17
- Windows 11 pro
Are you sure that other field types work? From your example it is not clear if you use Hibernate field-based annotation or getter-method-level annotations. I never used field based lifecycles but I assume you have to use the same place for the annotation on which you use your general Hibernate annotations.
Are you sure that other field types work? From your example it is not clear if you use Hibernate field-based annotation or getter-method-level annotations. I never used field based lifecycles but I assume you have to use the same place for the annotation on which you use your general Hibernate annotations.
I shortened the example. Of сource I used hibernate annotation something like @Column(name = "state"). Now we use workaround which bases on String field in our project.
Enum field is transient. Something like that.
@Transient
private transient State state;
@LifeCycleHookBinding(operation = UPDATE, phase = PRECOMMIT, hook = PaymentWorkflowEntityStateHook.class)
@Column(name = "state")
private String paymentState;
public void setState(State state) {
this.state = state;
this.paymentState = state.name();
}
@PostLoad
void populateTransientFields() {
if (paymentState != null) {
state = State.valueOf(paymentState);
}
}
My theory is that elide doesn't see the field because it is transient so the hook never fires. To verify, try removing transient and see if that resolves the issue. If that works, you can try annotating the field with both Transient and ComputedAttribute so elide sees it and the database doesn't.