Querying Postgresql using Hibernate (JPA) doesn't find table

后端 未结 1 1518
轻奢々
轻奢々 2021-01-13 03:26

I\'m developing an application using JPA with Hibernate and Postgresql. Using Netbeans wizard, I created entity classes from the existing database. The extract from one of t

相关标签:
1条回答
  • 2021-01-13 03:59

    Postgres (used to, not sure on the newer) convert table names to lower case. That's the preferred operating procedure. If you log your queries you'll see hibernate may be or may not be quoting your table name (I'd guess it isn't).

    Hibernate saving User model to Postgres

    Honestly, if you're running on Postgres you really should either configure hibernate properly, or, as I would look at it, normalize your database as tables shouldn't have a namespace collision (thus removing the problem).

    //From the article...

    @Entity
    @Table(name="\"User\"")
    public class User {
        ...
    }
    

    EDITED 07/31/12:

    This change must be done to the fields of the tables in the following way:

    For @Column, change the name of the column adding escaped ":

    @Column(name = "\"C_MODEL\"") 
    

    For @JoinColumn, change the name of the column adding `:

    @JoinColumn(name = "`TP_MODEL`")
    

    You will have to do it manually on the columns giving you errors.

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