java org.hibernate.exception.SQLGrammarException: 无法准备语句——Spring ROO

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25258495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:41:24  来源:igfitidea点击:

org.hibernate.exception.SQLGrammarException: could not prepare statement -- Spring ROO

javaspringhibernatehsqldbspring-roo

提问by TheByeByeMan

I'm Building and web App using the Spring Roo Tool. and while creating my classes via the roo shell console, I've used several times the option -permitReservedWordsto create some classes (e.g. Role, Group and User).

我正在使用 Spring Roo 工具构建和 Web 应用程序。在通过 roo shell 控制台创建我的类时,我多次使用该选项-permitReservedWords来创建一些类(例如角色、组和用户)。

After generating the CRUD Views, I get this exception :

生成 CRUD 视图后,我收到此异常:

"org.hibernate.exception.SQLGrammarException: could not prepare statement"

“org.hibernate.exception.SQLGrammarException:无法准备语句”

Then I realized that the problem occurs only for entities with reserved Names, so How can I force these entities name, if it's not possible how can I edit the names, because the refactor option in eclipse doesn't solve the problem, especial with a lot of AspectJ Files in the projects ...

然后我意识到问题只发生在具有保留名称的实体上,所以我如何强制这些实体名称,如果不可能我如何编辑名称,因为 eclipse 中的重构选项不能解决问题,尤其是项目中有很多 AspectJ 文件...

回答by eruiz

Note the JPA default table name is the name of the class (minus the package) with the first letter capitalized, this is why you need -permitReservedWords. Your entities User, Role, etc by default will be stored in User, Role, etc tables that are reserved words in almost all databases.

注意 JPA 默认表名是类名(减去包),首字母大写,这就是为什么你需要-permitReservedWords. 默认情况下,您的实体UserRole等将存储在UserRole等表中,这些表在几乎所有数据库中都是保留字。

To change the default behaviour, use the annotation "@Table(name="app_user")" (javax.persistence.Table) to specify/customize the database table name that stores the data of given Entity. For example, Userentity could be stored in uzertable.

要更改默认行为,请使用注释“@Table(name="app_user")”(javax.persistence.Table)指定/自定义存储给定实体数据的数据库表名称。例如,用户实体可以存储在uzer表中。