elide icon indicating copy to clipboard operation
elide copied to clipboard

@LifeCycleHookBinding doesn't work with ENUM

Open Sendvi41 opened this issue 1 year ago • 2 comments

Expected Behavior

@LifeCycleHookBinding should work with ENUM field

Current Behavior

@LifeCycleHookBinding doesn't work with ENUM field

Possible Solution

Steps to Reproduce (for bugs)

  1. Create Entity with Enum field
  2. Use @LifeCycleHookBinding for this field example ( @LifeCycleHookBinding(operation = UPDATE, phase = PRECOMMIT, hook = YourHook.class) StateEnum state' )
  3. Try to change entity using json API
  4. Hook will not work =(

Context

Your Environment

  • Elide version used: 7.0.1
  • Java 17
  • Windows 11 pro

Sendvi41 avatar Feb 20 '24 07:02 Sendvi41

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.

Brutus5000 avatar Feb 20 '24 12:02 Brutus5000

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);
       }
   }

Sendvi41 avatar Feb 20 '24 13:02 Sendvi41

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.

aklish avatar Feb 25 '24 00:02 aklish