Thanks John, that’s indeed a better workaround. It can still be simplified to :

   @Query("from Person")
   QueryResult<Person> findAllPersons();

But I still think it would be cool if empty “QueryResult findAllBy()” would 
work out of the box. With Spring Data you can do pretty much the same. I 
created following Jira issue for it:
https://issues.apache.org/jira/browse/DELTASPIKE-1239

__
Matti Tahvonen – +358 44 3029728 – Vaadin Ltd - vaadin.com


> On 15 Mar 2017, at 14:06 , John D. Ament <[email protected]> wrote:
> 
> Hi,
> 
> So here's the example from the page..
> 
> @Repository
> public interface PersonRepository extends EntityRepository<Person, Long>
> {
> 
>    @Query("select p from Person p where p.age between ?1 and ?2")
>    QueryResult<Person> findAllByAge(int minAge, int maxAge);
> 
> }
> 
> We're not using a predicate per-se, but its using an inlined query.
> Unfortunately, any method defined in EntityRepository uses a default
> handler that's not overridable (I found it hard to add Optional/Stream
> support).  I would do something like the documentation
> 
> @Repository
> public interface PersonRepository extends EntityRepository<Person, Long>
> {
> 
>    @Query("select p from Person p")
>    QueryResult<Person> findAllPersons();
> 
> }
> 
> Unless you're using the persistence operations as well, it may just be
> easier to not have the base interface.
> 
> John
> 
> On Wed, Mar 15, 2017 at 7:12 AM Matti Tahvonen <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>> Hi,
>> 
>> My colleague is preparing an example for Vaadin 8 that uses DeltaSpike
>> Data (as per my suggestion). We had a hard time finding a solution where
>> you could return QueryResult form a JPA Repository, without having any
>> predicates. We want to use QueryResult as it is easy to do sorting and
>> paging using it, but just want to get all results from the database. In
>> other words we’d need an alternative to findAll that returns QueryResult.
>> 
>> The workaround was to add a dummy predicate, but that’s not too pretty:
>> 
>> https://github.com/alejandro-du/lazy-loading-cdi-demo/blob/master/src/main/java/com/example/PersonService.java#L23
>> 
>> QueryResult  findBy() or QueryResult findAllBy() don’t seem to work. Any
>> ideas how this should be tackled?
>> 
>> __
>> Matti Tahvonen – +358 44 3029728 <+358%2044%203029728> – Vaadin Ltd -
>> vaadin.com <http://vaadin.com/>

Reply via email to