Reputation: 1688
I want to implement Repository with delete query.
@Repository
public interface LogRepository extends JpaRepository<Log, Integer>, JpaSpecificationExecutor<Log> {
@Modifying
@Query("delete from " + Log.class.getName() + " r where r.createdAt <= ?1")
int deleteByCreatedAt(LocalDateTime createdAt);
}
But I get error The value for annotation attribute Query.value must be a constant expression
Is there some way to implement this?
Upvotes: 1
Views: 860
Reputation: 9806
The query "delete from " + Log.class.getName() + " r where r.createdAt <= ?1"
is not constant indeed, as it will change with the change of the Log
class. But why would you want to keep this dynamic? Is not like you will change the table name in the database very often. Just define it statically and you will be good to go.
Upvotes: 2