Anuj Anuj - 1 year ago 954
Java Question

More than one table found in namespace (, ) - SchemaExtractionException

I have been facing this weird exception while trying to persist some values into a table using Hibernate in a Java application. However this exception occurs only for one particular table/entity for rest of the tables i am able to perform crud operations via Hibernate.

Please find below the Stacktrace and let me know if this is anyway related to java code is or its a database design error.

2016-04-28 11:52:34 ERROR XXXXXDao:44 - Failed to create sessionFactory More than one table found in namespace (, ) : YYYYYYY
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.XX.dao.XXXXXXXDao.main(
Caused by: org.hibernate.tool.schema.extract.spi.SchemaExtractionException: More than one table found in namespace (, ) : YYYYYYY
at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults(
at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(
at org.hibernate.tool.schema.internal.exec.ImprovedDatabaseInformationImpl.getTableInformation(
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.performMigration(
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(
at org.hibernate.internal.SessionFactoryImpl.<init>(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at org.hibernate.cfg.Configuration.buildSessionFactory(
at com.xx.dao.zzzzzzzzzzzzDAOFactory.configureSessionFactory(
at com.xx.dao.zzzzzzzzzzzzDAOFactory.buildSessionFactory(
at com.xx.dao.XXXXXXXXDao.main(

Thanks in advance for your help

Answer Source

I have had the same problem and was able to dig down to the code to find out the cause, at least in my case. I don't know whether it will be the same issue for you but this may be helpful.

From your stack trace I can see you have the set to upgrade the schema. As part of this, it is trying to look up the metadata for all the tables hibernate knows about and for one of them getting an ambiguous answer because the metadata query is returning more than a single row of table or view metadata.

In my case this was caused by our naming convention for tables. We had a table called (say) "AAA_BBB" for which this was going wrong. Now the use of an underscore in the table name is perfectly acceptable as far as I am aware and is quite common practice. However the underscore is also the SQL wildcard for a single character; looking in the code for the database metadata I can see it is doing a "WHERE table_name LIKE ..." in DatabaseMetaData.getTables(...) method, which is what hibernate is using here.

Now, in my schema I also had a second table called "AAA1BBB" and hence both of these matched the metadata lookup and so it returned a metadata row for each of these tables. The hibernate method is written to just fall down if the result set from the table metadata lookup returns more than one row. I would guess it should examine the available row(s) and find if there is one which is an exact match with the specified table name.

I tested this for both Oracle and MySQL with the same result.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download