[For confirmation] jpaBootstrap disallowDeletionOfDetached

Hi,

To authorize a deletion of a detached entity I overloaded the DefaultDeleteEventListenet and set jpaBootstrap to true, ok for you?

public class EfluidDeleteEventListener extends DefaultDeleteEventListener {
  public static final EfluidDeleteEventListener INSTANCE = new EfluidDeleteEventListener();

  @Override
  public void wasJpaBootstrap(boolean wasJpaBootstrap) {
    super.wasJpaBootstrap(false);
  }
}

public class IntegratorEventListenerRegistry implements Integrator {
  public static final IntegratorEventListenerRegistry INSTANCE = new IntegratorEventListenerRegistry();

  @Override
  public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
    eventListenerRegistry.setListeners(DELETE, EfluidDeleteEventListener.INSTANCE);
  }
}

What do you mean by “ok for you”? It’s up to you if you want these semantics. I’d suggest you to use EntityManager.getReference() to get a managed proxy instead and delete that. This way, you don’t have to select the entity but still can delete it.

1 Like

Its better with getReference and that work !
Thank you.