We are working on web application using Spring data JPA with hibernate.
In the application there is a field of compid in each entity. Which means in every DB call (Spring Data methods) will have to be checked with the compid.
I need a way that, this "where compid = ?" check to be injected automatically for every find method. So that we won't have to specifically bother about compid checks.
Is this possible to achieve from Spring Data JPA framework?
You cant actually use both of them in the same application.
I can use the findAll() method to select * from my_table to get all columns and rows.
The Iterable<T> findAll() method returns all entities that are saved to the database. The T findOne(Long id) method returns the entity whose id is given as method parameter.
Spring Data JPA supports find, read, query, count and get.
Maybe Hibernate‘s annotation @Where
will help you. It adds the passed condition to any JPA queries related to the entity. For example
@Entity
@Where(clause = "isDeleted='false'")
public class Customer {
//...
@Column
private Boolean isDeleted;
}
More info: 1, 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With