JPA @Transient fields being cleared before @PreUpdate method is called

后端 未结 2 1993
别跟我提以往
别跟我提以往 2021-02-19 05:04

I have an User Entity class that I\'m trying to do password hashing for. I thought that the easiest way to do this would be to create a password field annotated with @Transient

2条回答
  •  眼角桃花
    2021-02-19 05:56

    As mentioned in the above answer, this is by design in the spec. EclipseLink contains an event (postMerge) that is not part of the JPA spec that should be called in the right point in the cycle for you. In EclipseLink 2.1 The Descriptor Event Adaptor class can be registered using the regular @EventListeners annotation, pre 2.1 you will need to add the even using EclipseLink native API.

    @EntityListeners({
        a.b.MyEventListener.class,
    })
    

    package a.b;
    
    import org.eclipse.persistence.descriptors.DescriptorEvent;
    import org.eclipse.persistence.descriptors.DescriptorEventAdapter;
    
    public class MyEventListener extends DescriptorEventAdapter {
    
        public void postMerge(DescriptorEvent event) {
            //event.getSession();
            //event.getObject();
            //event.getOriginalObject();
        }
    }
    

提交回复
热议问题