K
K
Kentaro232016-06-23 21:55:25
Java
Kentaro23, 2016-06-23 21:55:25

How can you filter an Entity without querying the database and without a loop?

Please tell me if there is an analogue of Link from NET in JPA, so that you can filter the TestEntity loaded with records. For example, I made a request and loaded all the records from the TEST table, then, as needed, I select only the necessary records. Thanks in advance!
public List findResult() {
return em.createQuery("SELECT t FROM TestEntity t").getResultList();
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
geron, 2016-06-24
@kentaro23

JPA has its own object-oriented query language. In Hibernate it's HQL, in JPA it's JPQL.
https://ru.wikipedia.org/wiki/Java_Persistence_Que...

A
Alexander Kosarev, 2016-06-24
@jaxtr

If you need to filter the list of records retrieved from the database. then this can be done using lambdas and StreamAPI. Something like:

list.stream()
    .filter(entity -> "bar".equals(entity.getFoo()))
    .collect(Collectors.toList());

And in general it is necessary to filter in request to a DB.

K
Konstantin Malyarov, 2016-06-24
@Konstantin18ko

Uploaded where? In array?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question