"Table not found" exception with hibernate
I'm getting the following exception with hibernate:
10:18:14,795 INFO [SchemaValidator] Running schema validator
10:18:14,795 INFO [SchemaValidator] fetching database metadata
10:18:16,958 INFO [DatabaseMetadata] table not found: DUMMY_TABLE
10:18:16,963 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=bkoMdw-ear.ear/bkoMdw-ejb.jar#bkoMdw state=Create
javax.persistence.PersistenceException: [PersistenceUnit: bkoMdw] Unable to build EntityManagerFactory
(...)
Caused by: org.hibernate.HibernateException: Missing table: DUMMY_TABLE
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1127)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:359)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFacto开发者_如何学Gory(AnnotationConfiguration.java:867)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
The problem is that the table exists and the datasource file is correctly configured.
What I'm missing? Any advise to troubleshoot this?
Thanks in advance!
The problem is that you think the table exists and that the datasource is correctly configured while Hibernate knows that this isn't correct.
Increase the log levels and use -Dhibernate.show_sql=true
to enable logging for SQL statements. That should help to track this one down.
[EDIT] Also make sure you don't have white space before or after a @Table
annotation. If you have this annotation:
@Table(name = "myTable ") // Note the space after the name!!
Then Hibernate will use the quoted name to create the table (so you will have a table with the SQL name 'MYTABLE '
) but it won't always quote the name when you run queries.
I had the same problem with a view I used in my mapping. After I've disabled Hibernate's validation, it works correctly. Seems, that the validation has a problem with views.
Also make sure the case is correct. You might have it in the databse as dummy_table may be.
Worked for me when I changed @Table(name = "schema.table") To @Table(name = "table", schema = "schema")
I had the same issue with a mysql database. The issue was that I used Upper case names for tables. I lowered them down and now everything works.
I had a similar problem with postgresql and hibernate 5.2.10.
The table definitely existed. When I turned validate off, everything worked. It turned out that the table could probably not be found because hibernate could not handle no specified schema. It seemed related to: https://hibernate.atlassian.net/browse/HHH-11286.
I updated postgresql and the dialect (PostgreSQLXXDialect). The problem went away after that.
In my case, case sensitivity was important. While declaring table='DUMMY_TABLE' in hibernate mapping was completely working on Windows machine, it did not work after moving mysql server to linux system. I had to change all uppercase letters to lower cases such as table='dummy_table'
@Hendrik has the right idea. I had the same problem and I was able to fix the issue by adding the beans bellow to my applicaiton context file.
<bean id="dbUnitDatabaseConfig" class="com.github.springtestdbunit.bean.DatabaseConfigBean">
<property name="caseSensitiveTableNames" value="false"/>
<property name="qualifiedTableNames" value="true"/>
<property name="datatypeFactory">
<bean class="org.dbunit.ext.mysql.MySqlDataTypeFactory"/>
</property>
<property name="metadataHandler">
<bean class="org.dbunit.ext.mysql.MySqlMetadataHandler"/>
</property>
</bean>
<bean id="dbUnitDatabaseConnection" class="com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean">
<property name="databaseConfig" ref="dbUnitDatabaseConfig"/>
<property name="dataSource" ref="dataSource"/>
<property name="transactionAware" value="true"/>
<property name="schema" value="yourSchemaName"/>
</bean>
I got the same exception from hibernate. In my case, it was because the database user was not properly authorized to see the tables. The tables were definitively there on the database.
After I assigned the roles db_datareader to the user for this database it worked.
However, in another case, where the tables weren't actually there, I got exactly the same exception from hibernate. I cases where the tables are there, I think hibernate might show no more information because of security reasons.
I am using flyway db migration and for oracle, because of a single user, single schema limitation, I had to force my all microservices to use the same schema. Surprisingly few microservices was able to read the common table loading from the dependent library but one service which was getting created by Kubernetes deployment in between was failing with this error.
Below setting helped to fix it:
Set ddl-auto=none
# JPA Configuration
jpa:
database-platform: ${DB_DIALECT:org.hibernate.dialect.Oracle12cDialect}
hibernate:
ddl-auto: none
For me, I was getting this error after renaming my table, but it was still saying:
Missing table: OLD_NAME
even though I was certain I'd updated all the references.
It turns out I had to do a Maven Clean in Eclipse, and that fixed it.
In my case I am using H2. I had a column that was a reserved word (See H2 reserved words)
It was really frustrating as no error messages would be kicked out. The sql debugging showed the table was being created.
精彩评论