在namespace(,)中找到多个表 - SchemaExtractionException [英] More than one table found in namespace (, ) - SchemaExtractionException

查看:2375
本文介绍了在namespace(,)中找到多个表 - SchemaExtractionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在面对这个奇怪的例外,同时尝试在Java应用程序中使用Hibernate将一些值保留到表中。但是,这个异常只发生在一个特定的表/实体上,我可以通过Hibernate来执行crud操作。

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.

请在StackTrace下方找到,让我知道如果这是无论如何与java代码相关的还是其数据库设计错误。

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 object.org.hibernate.tool.schema.extract.spi.SchemaExtractionException: More than one table found in namespace (, ) : YYYYYYY
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.XX.dao.XXXXXXXDao.main(XXXXXXXXDao.java:45)
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(InformationExtractorJdbcDatabaseMetaDataImpl.java:381)
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(InformationExtractorJdbcDatabaseMetaDataImpl.java:279)
    at org.hibernate.tool.schema.internal.exec.ImprovedDatabaseInformationImpl.getTableInformation(ImprovedDatabaseInformationImpl.java:109)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.performMigration(SchemaMigratorImpl.java:252)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:137)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:110)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:64)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:458)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    at com.xx.dao.zzzzzzzzzzzzDAOFactory.configureSessionFactory(zzzzzzzDAOFactory.java:43)
    at com.xx.dao.zzzzzzzzzzzzDAOFactory.buildSessionFactory(zzzzzzzzzDAOFactory.java:27)
    at com.xx.dao.XXXXXXXXDao.main(XXXXXXXXDao.java:41)

提前感谢您的帮助

推荐答案

我有同样的问题,能够挖掘代码找出原因,至少在我的情况下。我不知道这是否会是同样的问题,但这可能是有帮助的。

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.

从你的堆栈跟踪我可以看到你有hibernate.hbm2ddl.auto设置升级架构。作为其中的一部分,它正在尝试查找hibernate知道的所有表的元数据,并且其中一个获得了一个模糊的答案,因为元数据查询返回的表格或视图元数据不止一行。

From your stack trace I can see you have the hibernate.hbm2ddl.auto 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.

在我的情况下,这是由我们的表的命名约定引起的。我们有一张名为(说)AAA_BBB的表,这是错误的。现在在表名中使用下划线是完全可以接受的,据我所知,是相当普遍的做法。但是下划线也是单个字符的SQL通配符;查看数据库元数据的代码,我可以看到它正在使用DatabaseMetaData.getTables(...)方法中的WHERE table_name LIKE ...,这是hibernate在这里使用的。

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.

现在,在我的架构中,我还有一个名为AAA1BBB的第二个表,因此这两个表与元数据查找相匹配,因此它返回了每个元数据行表。如果表元数据查找中的结果集返回多行,则hibernate方法被写入只是掉落。我会猜测它应该检查可用的行,并找到是否有与指定的表名完全匹配的行。

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.

我测试了这两个Oracle和MySQL具有相同的结果。

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

这篇关于在namespace(,)中找到多个表 - SchemaExtractionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆