0

For spring-data-jpa-datatables:4.3, how to make DataTablesRepository to return all entities, ignoring the Hibernate's @Where annotation?

This is an entity with Hibernate's @Where annotation:

@Entity
@SQLDelete(sql = "UPDATE vehicle SET deleted_at = NOW() WHERE id = ?")
@Where(clause = "deleted_at IS NULL")
public class Vehicle extends AbstractEntity implements Serializable {...}

And this is a corresponding repository extending spring-data-jpa-datatables's DataTablesRepository:

@Repository
public interface VehicleDataTableRepository extends DataTablesRepository<Vehicle, Long> {
}
Gera
  • 95
  • 4

2 Answers2

1

That's not possible. The @Where predicate is always applied. You can map the same table again to a different entity class without the @Where and query that instead if you want though or you create a filter (@Filter) instead of using @Where and just ensure the filter is always active except when you explicitly don't want the filter predicate to be applied. Also see: https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#pc-filter

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
0

You can write a native query like below.

@Query(value="SELECT * FROM table Name", nativeQuery=true)
public ignoreWhereClauseQuery(){}

The SQL in the @Query annotation must point the table's name and the fields' names (not entity's name).

Alien
  • 15,141
  • 6
  • 37
  • 57
  • spring-data-jpa-datatables has it's own implementation of `DataTablesRepository`, I doubt that the `nativeQuery` can help here. Please see github.com/darrachequesne/spring-data-jpa-datatables – Gera Jul 08 '21 at 10:14
  • You can create your own method and use native query for that. – Alien Jul 08 '21 at 13:24
  • Again, this is not the case. The purpose of the pring-data-jpa-datatables is to create queries dynamically under the hood, based on the GUI state. nativeQuery contradicts the very idea. – Gera Jul 12 '21 at 12:25