我们有一个由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实例(对于Users表,实际上),并且每次都由相同的操作触发,但我们似乎无法确定实际问题是什么。
答案 0 :(得分:1)
尝试使用最新版本的H2。您使用的是相对较旧的版本(2010-01-30版本1.2.128)。我很确定你会得到更好的错误信息,否则问题就会消失。
答案 1 :(得分:0)
启用Hibernate参数和SQL日志记录。例如,在log4j.properties文件中:
log4j.logger.org.hibernate=INFO, hibernate
log4j.logger.org.hibernate.SQL=DEBUG, hibernate
log4j.logger.org.hibernate.type=TRACE #******this is the most important piece
log4j.appender.hibernate=org.apache.log4j.RollingFileAppender
log4j.appender.hibernate.File=/blah/logs/hibernate.log
log4j.appender.hibernate.MaxFileSize=10024KB
log4j.appender.hibernate.MaxBackupIndex=5
log4j.appender.hibernate.layout=org.apache.log4j.PatternLayout
log4j.appender.hibernate.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n