1

I have done a job that reads data from a db and writes it in a file. It works fine with an Oracle DB. However, when I use it with Postgres I get the following error:

org.postgresql.util.PSQLException: ERROR: subquery in FROM must have an alias
Hint: Por ejemplo, FROM (SELECT ...) [AS] foo.
Position: 15
Error Code: 0

The reader is defined as follows:

<bean id="myReader"
class="org.springframework.batch.item.database.Jpa PagingItemReader">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="queryString" value="select c from CountryEntity c" />
<property name="pageSize" value="1000"/>
</bean>

Does anybody know if this is a common issue related with Postgres? Do I need to use a specific configuration?

1 Answer 1

1

You need to configure your JPA provider to use the PostGreSQL dialect.

E.g. for Hibernate, you would use a setup (persistence.xml) like this:

<persistence-unit name="somename" transaction-type="RESOURCE_LOCAL">
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
        <property name="hibernate.connection.url" value="jdbc:postgresql:sample"/>
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>
Sign up to request clarification or add additional context in comments.

1 Comment

Patrick, thank you very much for your answer. I have tried with the the configuration you mentioned, but the problem has not been solved. I do not know if I am missing something... I have added in a new answer the configuration I have tried. Is it enough with that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.