Announcement Announcement Module
Collapse
No announcement yet.
Select count(*) as count query for findAll(Pageable) is not being called Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Select count(*) as count query for findAll(Pageable) is not being called

    Hello,

    I have a JPA Entity ("Entidad") created with Roo as well as its Repository.

    I'd like to modify the count Query for the method findAll(Pageable) but the next approach is not working:

    Code:
    public interface EntidadRepository {//The extensions and annotations are coded in the _Roo_Jpa_Repository aspect
    
    	@Query(countQuery = "SELECT COUNT(*) FROM Entidad o")
    	public Page<Entidad> findAll(Pageable pageable);
    
    }
    This code is being called from the _Roo_DataOnDemand aspect, method init:

    Code:
        public void EntidadDataOnDemand.init() {
            int from = 0;
            int to = 10;
            data = entidadRepository.findAll(new org.springframework.data.domain.PageRequest(from / to, to)).getContent();
    But according to the logs, it's not using my custom query.

    What am I doing wrong?

    Greetings

  • #2
    Problem not yet solved

    After updating to Hibernate 4.3.0.Final (hibernate-core, hibernate-entitymanager. And 4.3.0.Final for hibernate-validator) the count select that it's builded is:

    Code:
    select count(*) as col_0_0_  from TABLE table0_ fetch first 2 rows only
    So I have no longer any problem.

    However, I still don't know how to modify a Query in a method that belongs to a JpaRepository.

    Am I the only one in the entire world with that issue?

    Greetings.

    Comment


    • #3
      Updated. See: Select count(*) as count query for findAll(Pageable) is not being called

      Comment


      • #4
        reference manual section 1.4.1 and override the method you need ?

        Comment


        • #5
          Thank you very much for your response.

          I read this section but I thought it didn't fit my needs because it's about adding behaviour, and what I want to do is to modify behaviour.

          However, thanks to your response, I realize that I could extend the SimpleJpaRepository<T, ID> and try to override the findAll method.

          Currently it's some kind of stubborness, because I no longer have problems after updating the Hibernate version, but I think the try is worth it.

          Let's see the next monday.

          Greetings.

          Comment

          Working...
          X