Announcement Announcement Module
Collapse
No announcement yet.
query method jpa not extract query with pageable Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • query method jpa not extract query with pageable

    i'm trying to create a query method on BookmarkRepository to retrieve all bookmarks of a user, like this:
    Code:
    Page<Bookmark> findByUser(User user, Pageable pageable);
    but this error happens:
    Code:
    Could not create query for public abstract org.springframework.data.domain.Page br.com.webbook.repositories.BookmarkRepository.findByUser_UserName(java.lang.String,org.springframework.data.domain.Pageable)! Reason: Your persistence provider does not support extracting the JPQL query from a named query thus you can't use Pageable inside your query method. Make sure you have a JpaDialect configured at your EntityManagerFactoryBean as this affects discovering the concrete persistence provider.
    if I do it like this...
    Code:
    List<Bookmark> findByUser(User user);
    everything works fine, but i want paginate the results.

  • #2
    The error message describes what is wrong:

    Code:
    Your persistence provider does not support extracting the JPQL query from a named query thus you can't use Pageable inside your query method. Make sure you have a JpaDialect configured at your EntityManagerFactoryBean as this affects discovering the concrete persistence provider.
    Could you add the configuration of your entity manager factory bean here?

    Comment


    • #3
      my persistence.xml:
      Code:
      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
        <persistence-unit name="development" transaction-type="RESOURCE_LOCAL">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <class>br.com.maykoone.domain.User</class>
          <class>br.com.maykoone.domain.Bookmark</class>
          <properties>
            <property name="hibernate.connection.username" value="app"/>
            <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.ClientDriver"/>
            <property name="hibernate.connection.password" value="app"/>
            <property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/tests"/>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
            <property name="hibernate.show_sql" value="true" />
            <property name="javax.persistence.validation.mode" value="none" />
          </properties>
        </persistence-unit>
      </persistence>
      my spring config:
      Code:
      ...
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
              <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
              <property name="persistenceUnitName" value="development" />
              <property name="jpaDialect">
                  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
              </property>
          </bean>
      
          <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
              <property name="entityManagerFactory" ref="entityManagerFactory" />
          </bean>
      
          <tx:annotation-driven transaction-manager="transactionManager" />
      
          <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
          <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
          
          <context:annotation-config />
      <jpa:repositories base-package="br.com.maykoone.repositories" />

      Comment


      • #4
        I would personally set the jpaVendorAdapter property of the LocalContainerEntityManagerFactoryBean class instead of manually specifying the used JPA dialect. The API documentation of the AbstractEntityManagerFactoryBean class has a great description about the meaning of this property:

        Specify the JpaVendorAdapter implementation for the desired JPA provider, if any. This will initialize appropriate defaults for the given provider, such as persistence provider class and JpaDialect, unless locally overridden in this FactoryBean.
        In your case, you could try to use the following configuration:

        Code:
        <bean id="hibernateJpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
                <property name="persistenceUnitName" value="development" />
                <property name="jpaVendorAdapter" ref="hibernateJpaAdapter"/>
        </bean>

        Comment

        Working...
        X