Question

We're using hibernate entitymanager to map our entities through JPA. And we are using HSQLDB in-memory database for unit testing. Everything was fine until a recent refactor to the model started causing the following error:

17:55:48.516 [main] WARN  o.h.util.JDBCExceptionReporter - SQL Error: -22, SQLState: S0002
17:55:48.517 [main] ERROR o.h.util.JDBCExceptionReporter - Table not found in statement

I can't post the SQL in question, but can anyone give me pointers as to the possible causes of the above error? especially since I know the code was working before. It seems like hibernate is generating invalid sqls because of the refactor?

Was it helpful?

Solution

Well, is the table actually there? Enable SQL output for Hibernate and check it against the actual database schema.

Your refactoring may have been botched (entity and table were renamed; named query was not updated).

Or you may have an older class(es) somewhere in classpath causing wrong annotations to be read.

OTHER TIPS

This could also indicate a mismatch between the JDBC driver and the Hibernate dialect.

We got this when the JDBC driver connection was HSQLDB and the Hibernate dialect was org.hibernate.dialect.Oracle10gDialect.

The corresponding exception message: [ERROR]: could not get database metadata java.sql.SQLException: Table not found in statement [ select sequence_name from all_sequences]

I had this problem too, in my case I had something like this in the entity

@Column(name = "AVAIL_TARGET_PERCENT", columnDefinition = "number(5,2)", nullable = false)

Just avoid the columnDefinition (take it out!) and you should be fine. I did that, and the problem was fixed

We were also getting the same exception. It turns out the property hibernate.dialect was set as org.hibernate.dialect.Oracle10gDialect with H2 data base serving as a datasource. The solution is to remove hibernate.dialect and do not use any value. Hibernate have the capability to auto detect dialect based metadata retrieved from datasource configuration
For more information on how hibernate auto-detects dialect
https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/portability.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top