0
@Modifying(clearAutomatically = true)
@Query("update RssFeedEntry feedEntry set feedEntry.read =:isRead where     feedEntry.id =:entryId")
void markEntryAsRead(@Param("entryId") Long rssFeedEntryId, @Param("isRead") boolean isRead);

For example I have a lot of similar entity : RssFeedEntry ... OtherFeedEntry All of them has feedEntry.read and feedEntry.id fields (for exaple described in separate @MappedSuperclass abstract class) but mapped to different tables. So on to perform update I have to write similar method for every entity with

update <AnyOfFeedEntryr> feedEntry set feedEntry.read =:isRead where     feedEntry.id =:entryId 

Is it any way to avoid copy past for every entity?

Alstresh
  • 583
  • 2
  • 4
  • 16

1 Answers1

0

Of course you can do that in object oriented languages easily. For example, in Spring data as you probably use there is an interface called Repository and an interface called CrudRepository which implements Repository, and an interface called PagingAndSortingRepository.

For example if you use CrudRepository you can use CRUD operations without having to write a single line of code.

Just like that, you can extend Repository, CrudRepository or any other interface you are using and add your own method, in your case markEntryAsRead, and use this interface in your actual service like MyService extends MyCustomRepository

Here is an implementation example you can use in your app: http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/#repositories.custom-implementations

SerhatCan
  • 590
  • 1
  • 7
  • 26