---
title: "Hibernate中的关键字和怪问题"
author: "steeven"
date: "2009-06-22T22:47:15Z"
tags: []
categories: ["企业架构"]
slug: "hibernate"
draft: false
lastmod: "2009-06-22T22:47:15Z"
id: 413157
url: "https://steeven.iteye.com/blog/413157"
---

在测试JPA的过程中，对象用'Table'命名，关键字，结果会怎样？死翘翘,hibernate 3.3.1
ERROR  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 'Table (title) values (null)' at line 1
真是不敢想象啊。hibernate都这把年纪了，还没解决这种低级问题@_@


从代码看了半天, Dialect似乎有Quote支持，还有openquote和closequote，但是好像只有query的时候会用到。

OK, 我们改名为Demo，没有报错，但是更诡异的状况发生了：

```java
mo = em.merge(mo);

```

这个mo如果以前主键是自增的，并且已经赋值，原来是deattached状态，现在会变成attached状态，但是，id也会自动变成最新值。。。。。。。

换成Foo后一切正常。。。。。。


那么关键字怎么办呢？官方文档中答案：
5.4. SQL quoted identifiers
使用`，就是波浪号~那个键

```xml
<class name="LineItem" table="`Line Item`">
    <id name="id" column="`Item Id`"/><generator class="assigned"/></id>
    <property name="itemNumber" column="`Item #`"/>
    ...
</class>
```



那么那些单词是关键词呢？不清楚，怀疑一切吧～～