本文介绍了映射称为“组”的表在Hibernate中为DB2和HSQLDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为的表,我正在尝试使用hibernate进行DB2映射,表名是一个保留字,它必须在HSQLDB中引用。但是,DB2不喜欢引用的表名。

I have a table called group, that I am trying to map using hibernate for DB2 and HSQLDB. Table name group is a reserved word and it must be quoted in HSQLDB. However DB2 does not like quoted table name.

所以这个映射在HSQLDB中工作,但不在DB2中:

So this mapping works in HSQLDB but not in DB2:

@Entity
@Table(name="`group`")
public class Group {

映射在DB2中出现以下错误(进行涉及组表的查询):

Mapping results in following error in DB2 (making a query that involves Group table):


Caused by: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: SCHEMA_NAME.group
    at com.ibm.db2.jcc.b.hh.c(hh.java:1662)
    at com.ibm.db2.jcc.b.hh.d(hh.java:1650)
    at com.ibm.db2.jcc.b.hh.a(hh.java:1219)
    at com.ibm.db2.jcc.c.db.g(db.java:139)
    at com.ibm.db2.jcc.c.db.a(db.java:39)
    at com.ibm.db2.jcc.c.t.a(t.java:34)
    at com.ibm.db2.jcc.c.sb.f(sb.java:142)
    at com.ibm.db2.jcc.b.hh.n(hh.java:1190)
    at com.ibm.db2.jcc.b.ih.eb(ih.java:1997)
    at com.ibm.db2.jcc.b.ih.d(ih.java:2439)
    at com.ibm.db2.jcc.b.ih.V(ih.java:492)
    at com.ibm.db2.jcc.b.ih.executeQuery(ih.java:475)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    at org.hibernate.loader.Loader.doQuery(Loader.java:674)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
    ... 71 more

这在DB2中有效但不在HSQLDB中:

And this works in DB2 but not in HSQLDB:

@Entity
@Table(name="group")
public class Group {

映射HSQLDB中的以下错误(创建组表):

Mapping results in following error in HSQLDB (creating the Group table):


WARN hibernate.ExtendedAnnotatedSessionFactoryBean - Unsuccessful schema statement: create table group  ( *details omitted* )
java.sql.SQLException: Unexpected token: GROUP in statement [create table group]
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.executeUpdate(Unknown Source)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.executeSchemaStatement(LocalSessionFactoryBean.java:1000)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.executeSchemaScript(LocalSessionFactoryBean.java:972)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean$2.doInHibernate(LocalSessionFactoryBean.java:912)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:338)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.createDatabaseSchema(LocalSessionFactoryBean.java:906)
  ...

我正在使用和分别为DB2和HSQLDB。

I am using org.hibernate.dialect.DB2Dialect and org.hibernate.dialect.HSQLDialect for DB2 and HSQLDB, respectively.

如何进行相同的映射同时为两个数据库工作?

How can I make the same mapping work for the both databases simultaneously?

推荐答案

我最终做了为group创建别名组,并在HSQLDB中更改表名,这解决了我的问题。现在我映射表,不再有此问题。

I ended up doing create alias groups for group; in DB2 and changing table name in HSQLDB, which solved my problem. Now I map groups table, and there are no longer this problem.

这篇关于映射称为“组”的表在Hibernate中为DB2和HSQLDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:16