【问题标题】:Pageable support for Spring Data JPA having jndi look up for entityManagerFactory具有 jndi 查找 entityManagerFactory 的 Spring Data JPA 的可分页支持
【发布时间】:2015-06-15 21:48:19
【问题描述】:

我关注 http://terasolunaorg.github.io/guideline/1.0.x/en/ArchitectureInDetail/Pagination.html 为我的 MVC 应用程序实现分页支持

当我尝试启动 JBoss 服务器时,

nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.repo.MyRepository.searchEntitySC(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.util.Date,java.lang.String,java.util.Date,java.lang.String,java.lang.String,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.

我试着关注,http://forum.spring.io/forum/spring-projects/data/99613-you-cannot-use-pageable-as-method-parameter-if-your-persistence-provider-cannot-extra

但我不知道如何为 entityManagerFactory 应用建议的配置

因为我的 jpa-config.xml 包含

  <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:jboss/pu/pc" />

欢迎任何其他更好的建议!

环境

  1. JBoss 企业应用平台 - 版本 6.2.0.GA

  2. spring-data-jpa-1.4.3.RELEASE.jar

  3. hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar

standalone.xml 包含:

  <datasource jndi-name="java:jboss/datasources/pc" pool-name="pcdatapool" enabled="true" use-ccm="false">
 <connection-url>jdbc:oracle:thin:@localhost:1521:mysid</connection-url>
                <driver>oracle</driver>
                <security>
                    <user-name>XXX</user-name>
                    <password>xxx</password>
                </security>
            </datasource>

persistence.xml

  <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="pcem">
       <jta-data-source>java:jboss/datasources/pc</jta-data-source>
    <mapping-file>META-INF/orm.xml</mapping-file>
    <class>xxx.YYYYY</class>
     ...
    <class>yyyy.AAAAAAAAAA</class>      
    <properties>
        <property name="hibernate.jdbc.batch_size" value="50" />
        <property name="hibernate.default_batch_fetch_size" value="50" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
        <!-- Use log category 'org.hibernate.SQL' to level 'debug' to output SQL from hibernate -->
        <property name="hibernate.show_sql" value="false" />
        <property  name="hibernate.format_sql" value="false"/>
        <!-- Use generate statistics this will help query performance tunning  -->
        <property  name="hibernate.generate_statistics" value="false"/>
    </properties>
</persistence-unit>

【问题讨论】:

    标签: spring-data-jpa


    【解决方案1】:

    在standalone.xml 文件中删除前缀java:。然后在持久性配置文件中引用您在standalone.xml 中的jndi 名称,但带有前缀。所以:

    persistence.xml

    <jee:jndi-lookup id="myDatasource" jndi-name="java:jboss/datasources/pc" />
    <mapping-file>META-INF/announcement-queries.hbm.xml</mapping-file>
    

    jboss.datasource.xml

    <datasource jndi-name="jboss/datasources/pc" pool-name="pcdatapool" enabled="true" use-ccm="false">
    ...
    </datasource>
    

    applicationContext.xml (Spring)

    <bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="myDatasource" />
            <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="false" />
                <property name="showSql" value="${hibernate.show_sql}" />
            </bean>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.use_sql_comments">${hibernate.format_sql}</prop>
                <prop key="hibernate.connection.isolation">1</prop>
                <prop key="hibernate.configurationClass">org.hibernate.cfg.AnnotationConfiguration</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                <prop key="hibernate.default_batch_fetch_size">100</prop>
                <prop key="hibernate.id.new_generator_mappings">true</prop>
            </props>
        </property>
        <property name="packagesToScan" value="com.mypacjage" />
    </bean>
    

    【讨论】:

    • 如何配置JpaDialect?
    • 感谢您的更新。在问题中添加了我的 persistence.xml。如果我理解了您的答案,我认为persistence.xml 中的 可以不用在applicationContext.xml 中使用META-INF/orm.xml
    • 映射文件可以进入示例中添加的 persistence.xml...
    • 不管怎样,你的persistence.xml是对的。您可以使用以下方法扫描您的实体类: 在您的 persistence.xml 文件中.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 2013-09-15
    • 2014-12-11
    • 1970-01-01
    • 2015-06-18
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多