Hibernate围绕columnDefinition加入反引号 [英] Hibernate putting backticks around columnDefinition
问题描述
@Column(name = <数据库>)在数据库中有一列,在实体类中定义如下: lastlogindate,columnDefinition =TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)
私人时间戳lastlogindate;
正在生成的 create table
命令如下所示:
pre $ create table usermaster(
lastlogindate`TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP`)
而有效的是
create table usermaster(
lastlogindate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)
Hibernate报告创建表时出现以下错误:
您的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以便在'
TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
,
附近使用正确的语法。
无法理解为什么要添加额外的勾号以及如何避免它。
版本详细信息如下: p>
- HIBERNATE VERSION:4.3.8.Final
- MySQL版本:5.6.26
- MySQL方言信息:
< ; property name =dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =transaction.factory_class>
org.hibernate.transaction.JDBCTransactionFactory< / property>
< property name =current_session_context_class>线程< / property>
< property name =show_sql> true< / property>
< property name =hibernate.connection.autocommit> false< / property>
< property name =hibernate.globally_quoted_identifiers> true< / property>
请删除以下配置行:
< property name =hibernate.globally_quoted_identifiers> true< / property>
这可能不是必需的,几乎肯定会导致您遇到的问题。
更新:
这个问题最终通过将普通MySQL改为MySQL5来解决:
org.hibernate.dialect.MySQL5Dialect
I have a column in the database which has been defined as follows in the entity class:
@Column(name="lastlogindate", columnDefinition ="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
private Timestamp lastlogindate;
The create table
command that is being generated is as follows:
create table usermaster (
lastlogindate `TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP`)
while what works is
create table usermaster (
lastlogindate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)
Hibernate reports the following error while creating tables:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
,
Unable to understand why extra ticks are being added and how to avoid it.
The version details are as follows:
- HIBERNATE VERSION: 4.3.8.Final
- MySQL version:5.6.26
- MySQL Dialect information:
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.autocommit ">false</property>
<property name="hibernate.globally_quoted_identifiers">true</property>
Please remove the following config line:
<property name="hibernate.globally_quoted_identifiers">true</property>
This is likely not needed and almost surely causing the problem you experience.
UPDATE:
The issue was finally solved by changing the dialect to MySQL5 from generic MySQL:
org.hibernate.dialect.MySQL5Dialect
这篇关于Hibernate围绕columnDefinition加入反引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!