Skip to content

Add possbility to return Entity from delete<...>ById(id: MyId) method #3995

@ars-java

Description

@ars-java

I try to use derived delete method to get deleted entity after deleting, but every of such signatures

fun removeMyEntityById(id: MyId): Optional<MyEntity>
fun removeMyEntityById(id: MyId): MyEntity?
fun deleteMyEntityById(id: MyId): Optional<MyEntity>
fun deleteMyEntityById(id: MyId): MyEntity?

throws

class java.lang.Integer cannot be cast to class ...MyEntity (java.lang.Integer is in module java.base of loader 'bootstrap'; MyEntity is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @50f8f031)

Every time Spring JPA returns count of deleted entities.

Default implementation of deleteById in SimpleJpaRepository use findById to select deleting entity but doesn't return it too.

	@Override
	@Transactional
	public void deleteById(ID id) {

		Assert.notNull(id, ID_MUST_NOT_BE_NULL);

		findById(id).ifPresent(this::delete);
	}

I think that it will be good if we can use such signatures to return entity removed by Id

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions