Hibernate + PostgreSQL : relation does not exist - SQL Error: 0, SQLState: 42P01

前端 未结 3 1566
情歌与酒
情歌与酒 2021-01-04 12:22

I am having some problems trying to work with PostgreSQL and Hibernate, more specifically, the issue mentioned in the title. I\'ve been searching the net for a few hours now

相关标签:
3条回答
  • 2021-01-04 12:57

    Another answer may be to check schema permissions - which may be useful for others who happen to come across the subject heading of this question. I had the same exact symptoms regarding the error message which was;

    <SQL Error: 0, SQLState: 42P01>
    <ERROR: relation "tablename" does not exist>
    

    The solution was to enable permissions on that schema for the user I was using to log in with.

    Also: Noting that a good diagnostic tool here is to log into the postgres command line console with the same user your program is using and attempt to access the table and schema in the same way.

    0 讨论(0)
  • 2021-01-04 13:11

    I've just solved the same / similar problem by specifying the schema.

    @Entity
    @Table(name = "mytable", schema="myschema")
    public class MyTable implements Serializable {
        ...
    
    0 讨论(0)
  • 2021-01-04 13:13

    Your JDBC URL is "jdbc:postgresql:postgres/tommy" which is unusual. The documentation suggests "jdbc://hostname/databasename". Modern installations come with a "postgres" database that almost definitely isn't what you want to connect to; I don't know how strict the JDBC driver's URL parsing is.

    What are you expecting your database name and hostname to be? e.g. what are your parameters to psql to connect to the database that way?

    Tip: in postgresql.conf, some settings you may consider:

    log_connections = on
    log_disconnections = on
    log_line_prefix = '%t %c %q%u@%h:%d '
    

    If the error is what I think (you're connecting to the wrong database), this would log things like the database name along with the error in your postgresql.log file.

    0 讨论(0)
提交回复
热议问题