Eclipselink仅在运行测试时在PARTITION上提供syntaxError

时间:2013-01-15 10:16:38

标签: sql oracle jpa junit eclipselink

我在使用本机SQL查询时遇到问题,当我正常运行代码时,该查询工作正常,但是给了我:

[EL Warning]: 2013-01-15 10:24:04.462--UnitOfWork(2230747)--
Exception [EclipseLink-4002] (Eclipse Persistence Services - 
2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException

Internal Exception: java.sql.SQLSyntaxErrorException: Syntax error: Encountered
"PARTITION" at line 1, column 109.

Error Code: 30000
Call: SELECT COUNT(*) FROM (SELECT p.PRICE_ID, p.PRODUCT_ID, p.PRICE, 
p.TEXT, row_number() OVER (PARTITION BY p.PRODUCT_ID ORDER BY p.PRICE_DT DESC) rn, 
p.PRICE_DT FROM PRICE_T p LEFT JOIN STORE_T b ON p.STORE_ID = 
b.STORE_ID WHERE (p.CHAIN_ID = ? AND p.PRICE_TYPE = 'NORMAL') OR
(p.PRICE_TYPE = 'SOMETHINGELSE' AND b.OTHERSTORE_ID IN (1,2)) ) WHERE rn = 1
bind => [1 parameter bound]

Query: DataReadQuery(sql="SELECT COUNT(*) FROM (SELECT p.PRICE_ID, p.PRODUCT_ID, p.PRICE, 
p.TEXT, row_number() OVER (PARTITION BY p.PRODUCT_ID ORDER BY p.PRICE_DT DESC) rn, 
p.PRICE_DT FROM PRICE_T p LEFT JOIN STORE_T b ON p.STORE_ID = 
b.STORE_ID WHERE (p.CHAIN_ID = ? AND p.PRICE_TYPE = 'NORMAL') OR
(p.PRICE_TYPE = 'SOMETHINGELSE' AND b.OTHERSTORE_ID IN (1,2)) ) WHERE rn = 1")

完全相同的查询在正常运行我的代码时完全没有任何问题。这是我的persistence.xmls:

persistence.xml(test)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="test-pu" transaction-type="RESOURCE_LOCAL">
            <!-- all entit-classes are here -->
    <exclude-unlisted-classes>false</exclude-unlisted-classes>  
    <properties>
        <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:test;create=true" />
        <property name="javax.persistence.jdbc.user" value="test" />
        <property name="javax.persistence.jdbc.password" value="test" />

         <!--  EclipseLink should create the database schema automatically --> 
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
        <property name="eclipselink.target-database" value="Derby"/>
    </properties>
</persistence-unit>

persistence.xml(正常)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="pu" transaction-type="JTA">
    <jta-data-source>mydatasource</jta-data-source>
            <!-- all entit-classes are here --> 
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="eclipselink.query-results-cache" value="false"/>
        <!--
        <property name="eclipselink.logging.level" value="FINE"/>
        <property name="eclipselink.logging.parameters" value="true"/>
        <property name="eclipselink.logging.logger" value="DefaultLogger"/>
        -->
    </properties>
</persistence-unit>

PriceRepositoryTest.java - testGetAmountOfPricesForChain1()

@Test
public void testGetAmountOfPricesForChain1() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("test-pu");
    EntityManager em = emf.createEntityManager();
    try {
        PriceRepository repository = new PriceRepositoryImpl(em);
        long amount = repository.getAmount(STORES_IN_CHAIN_1);
        assertEquals(PRICES_CHAIN_1.size(), amount);
    } finally {
        em.close();
    }
}

我试过谷歌搜索,但我没有找到任何东西。关于什么可能出错的任何想法?

1 个答案:

答案 0 :(得分:1)

您正在连接到Derby,而不是Oracle数据库。很可能Derby不支持这种语法。

相关问题