我们有一个由 Hibernate 支持的 Spring webapp 用于存储。最近,我们在使用我们的 Hibernate 存储对象之一执行查找时注意到了一些问题。这是堆栈跟踪:
org.h2.jdbc.JdbcSQLException: General error: "java.lang.RuntimeException: object already exists: TABLES"; SQL statement:
SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=? [50000-128]
at org.h2.message.Message.getSQLException(Message.java:110)
at org.h2.message.Message.convert(Message.java:287)
at org.h2.command.Parser.prepareCommand(Parser.java:256)
at org.h2.engine.Session.prepareLocal(Session.java:417)
at org.h2.engine.Session.prepareCommand(Session.java:378)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1074)
at org.h2.jdbc.JdbcConnection.getQueryTimeout(JdbcConnection.java:679)
at org.h2.jdbc.JdbcStatement.getQueryTimeout(JdbcStatement.java:547)
at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:299)
at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
at org.hibernate.loader.Loader.doQuery(Loader.java:770)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2449)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
at org.hibernate.loader.Loader.list(Loader.java:2187)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.ourapp.hibernate.HibernateDao.lookup(HibernateDao.java:173)
我无法准确确定问题所在 - SQL 是否试图插入 TABLES 对象?
我们的 HibernateDao.lookup() 方法,第 173 行:
172: Query query = session.createQuery("from " + entityClazz.getName() + " as entity where entity." + field + "='" + value + "'");
173: return query.list();
这似乎总是发生在同一个 HibernateDao 实例上(对于用户表,本质上),并且每次都由相同的操作触发,但我们似乎无法确定实际问题是什么。