quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Put in line delete method of Quakus Panache Commons JPA methods with Spring Data Commons.

Open schmittjoaopedro opened this issue 3 years ago • 1 comments

Description

Looking at the Spring implementation of CrudRepository backed by SimpleJpaRepository there are some divergences to Quarkus AbstractJpaOperations. The method delete(Object entity) on Spring tries to find the entity first through the entity manager before calling the delete. This helps a lot when you have a detached entity you want to delete, as you don't need to wrap the call in any upper transaction.

Reference:

Implementation ideas

Put in line Quarkus's AbstractJpaOperations with Spring's SimpleJpaRepository by doing something similar to:

    public void delete(Object entity) {
        EntityManager em = getEntityManager(entity.getClass());
        Class<?> type = ProxyUtils.getUserClass(entity);
        Object existing = em.find(type, entityInformation.getId(entity));
	if (existing == null) {
	     return;
	}
	em.remove(em.contains(entity) ? entity : em.merge(entity));
    }

schmittjoaopedro avatar Aug 08 '22 13:08 schmittjoaopedro

/cc @FroMage, @geoand, @loicmathieu

quarkus-bot[bot] avatar Aug 08 '22 13:08 quarkus-bot[bot]