TAMULib / Weaver-Webservice-Core

An open source Spring-boot webservice framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ordered Entity removal breaks when there are multiple Entity types sharing one table

jsavell opened this issue · comments

When multiple Entity types share one table, position values will be duplicated.

Under these conditions, OrderedEntityService.findByPosition fails to return a unique entity value, leading to a non-unique result error and failure to delete.

public Object findByPosition(Class<?> clazz, Long position) {

My implementation suggestion is to refactor the OrderedEntityService to separate the deletion and reorder logic.

Client apps would then be able to override the deletion mechanism if needed, while still letting the reorder, which relies on the entity manager and more complex logic, do what it needs to do.

I do not think separating deletion from reordering is the right approach. For an ordered entity when a delete occurs you must reorder or will have corrupt ordering. Reorder must continue to be a side-effect of deletion. I do think the extensibility of this service could be improved to afford to delete/reorder by a combination of properties in addition to the position.

I would recommend an additional method for overriding to add additional properties to the query conditions in conjunction with the position column.