Search code examples
javadatabasespring-roo

spring roo conditional database request


Is there any automatic way to create conditional database request with Spring roo? For example, I have Book class and this class has page attribute. I want to list books which has more than 100 page.


Solution

  • There is no way to generate it automatically, but you can create it on your Book class. By example:

    @RooJavaBean
    @RooToString
    @RooJpaActiveRecord
    public class Book {
    
    
       public int pages;
    
       // ...
       // ...
       // ...
       public static List<Book> findLargeBooks() {
    
            return entityManager().createQuery(
                "Select o from Book o where o.pages > 100", Book.class).getResultList();
    
       }
    
    
    }