0

I have recently moved to postgres 10.1 database from oracle. I created all the tables manually via sql queries and made sure that I do not use any double quotes around table/column names.

CREATE TABLE MYSCHEMA.SOMETABLE (ID VARCHAR(20) NOT NULL primary key, DISPLAYTEXT VARCHAR(100)));// skipping other column names for brevity

Entity Class in code

@Entity
@Table(name = "MYSCHEMA", schema = "SOMETABLE")
public class SomeTable implements Serializable {

    private static final long serialVersionUID = -4856666041227614340L;
    @Column(name = "VERSION")
    private String version;

    @Column(name = "DISPLAYTEXT")
    private String displayText;

    //other columns
}

Using Jpa repository, I am querying this table.

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef  = "someEntityManagerFactoryContentDB",
        transactionManagerRef = "sometransactionManagerContentDB",
        basePackages = {"com.somepath.repository.content"})
public interface SomeSearchConfigRepository extends JpaRepository<SomeTable, String> {
    List<SomeTable> findBySearchTypeAndActiveOrderBySequenceAsc(
            String searchType, String active);
}

The issue is that it's not able to find this table and throws below error.

2019-06-24 09:56:26,781  WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper:SQL Error: 0, SQLState: 42P01
2019-06-24 09:56:26,782 ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper:ERROR: relation "MYSCHEMA.SOMETABLE" does not exist

Sql generated as per the logs

Hibernate:
    /* select
        generatedAlias0
    from
        SomeTable as generatedAlias0
    where
        (
            generatedAlias0.searchType=:param0
        )
        and (
            generatedAlias0.active=:param1
        )
    order by
        generatedAlias0.sequence asc */ select
            myalias_."ID" as ID1_3_,
            myalias_."ACTIVE" as ACTIVE2_3_,
            myalias_."COLUMNNAME" as COLUMNNA3_3_,
            myalias_."DATATYPE" as DATATYPE4_3_,
            myalias_."DISPLAYTEXT" as DISPLAYT5_3_,
            myalias_."LENGTH" as LENGTH6_3_,
            myalias_."LINKCOLUMN" as LINKCOLU7_3_,
            myalias_."LINKSEARCH" as LINKSEAR8_3_,
            myalias_."LOOKUPCOLUMN" as LOOKUPCO9_3_,
            myalias_."LOOKUP_CATEGORY" as LOOKUP_10_3_,
            myalias_."MULTISELECT" as MULTISE11_3_,
            myalias_."REFERENCEKEY" as REFEREN12_3_,
            myalias_."REFERENCETABLENAME" as REFEREN13_3_,
            myalias_."REFERENCEVALUE" as REFEREN14_3_,
            myalias_."SEARCHTYPE" as SEARCHT15_3_,
            myalias_."SEQUENCE" as SEQUENC16_3_,
            myalias_."TABLENAME" as TABLENA17_3_,
            myalias_."VERSION" as VERSION18_3_
        from
            "MYSCHEMA"."SOMETABLE" myalias_
        where
            myalias_."SEARCHTYPE"=?
            and myalias_."ACTIVE"=?
        order by
            myalias_."SEQUENCE" asc

Is it that somehow the annotations in entity classes causing this issue? What's going wrong here and how can I fix this issue with minimal changes in my code ?

1
  • 1
    You need to tell your obfuscation layer to stop quoting the names. Did you try @Table(name = "myschema", schema = "sometable")? Commented Jun 24, 2019 at 11:21

1 Answer 1

1

I assume that you are using Spring Boot.

One option is to tell Hibernate to don't quote the names

spring.jpa.properties.hibernate.globally_quoted_identifiers=false

Or the other option is to create your tables also with quotes and go for all UPPERCASE names

Sign up to request clarification or add additional context in comments.

2 Comments

I am using <prop key="hibernate.globally_quoted_identifiers">true</prop> in my xml file. The reason for this is that I have few of the tables which are using reserved words as column names. I have the need of running the same code on oracle as well as on myql/postgres. So to make sure I do not use db specific escape characters, i used the above property.
OK But then with Postgresql the tables are case sensitive. I assume that your tables and columns are now lower case and your mapping has upper case names.

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.