JPA with Hibernate 3.6.8.Final, PostgreSQL 9.1, SQLGrammarException - configuration issue? Weird SQL statement

我是研究僧i 提交于 2019-12-04 08:37:58
Piotr Nowicki

The @Table("\"...\"") construct is to force the JPA provider to use the exact value you provide (i.e. use the exact case of the table name).

Moreover, it's similar in the PostgreSQL world. If you invoke CREATE TABLE and specify the table name in quotes than it will create the table with the exact name you specify (not only the case but also the semantics - in this way you can even create a table named TABLE):

CREATE TABLE "TeSt" ( id int PRIMARY KEY NOT NULL )

will result in table TeSt8.

CREATE TABLE TeSt2 ( id int PRIMARY KEY NOT NULL )

will result in table test2.

Hence, to query for "TeSt" table you will need to execute SELECT * FROM "TeSt" (not SELECT * FROM TeSt).

So, if you create a table with CREATE TABLE "SAMPLE" you need to specify @Table(name="\"SAMPLE\"") in order to get it worked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!