0

我在正常运行我的代码时工作正常的本机 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(测试)

<?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();
    }
}

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

4

1 回答 1

1

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

于 2013-01-15T10:51:26.690 回答