Hibernate saving User model to Postgres

前端 未结 2 1076
广开言路
广开言路 2020-12-01 20:38

I\'m using Postgres via Hibernate (annotations), but it seems to be falling over dealing with a User object:

12:09:16,442 ERROR [SchemaExport] Unsuccessful:          


        
相关标签:
2条回答
  • 2020-12-01 21:28

    You need to escape the table name when using reserved keywords. In JPA 1.0, there is no standardized way and the Hibernate specific solution is to use backticks:

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

    In JPA 2.0, the standardized syntax looks like this:

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

    References

    • Hibernate Core documentation
      • 5.4. SQL quoted identifiers
    • JPA 2.0 specification
      • 2.13 Naming of Database Objects
    0 讨论(0)
  • 2020-12-01 21:32

    User is a key word, find a better name or use quotes: "User". (bad idea imho, but it works if you do it everywhere)

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