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

后端 未结 10 1256
执念已碎 2021-02-20 18:52

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 parti

  • 2021-02-20 19:01

    Seems the property set to update is causing the issue here. Try removing it from your hibernate config xml.

    0 讨论(0)
  • 2021-02-20 19:01

    Simply, if u are using two schemas then u will get this error. To resolve this error u can use these steps :

    1. You need to delete extra schema.
    2. Or u can define default schemas or that schema are u using.
    0 讨论(0)
  • 2021-02-20 19:04

    We had a Spring Data / JPA application and this error started happening after upgrading to Postgres 10.6 (from 10).

    Our solution was as follows, in our JPA configuration class: note the new commented line,

    props.put("", "none"); //POSTGRES 10 --> 10.6 migration


    @EnableJpaRepositories(basePackages = "app.dao")
    @ComponentScan(basePackages = { "app.service" })
    public class JpaConfig {
        DataSource dataSource;
        public Map<String, Object> jpaProperties() {
            Map<String, Object> props = new HashMap<String, Object>();
            props.put("hibernate.dialect", PostgreSQL95Dialect.class.getName());
            props.put("", "none"); //POSTGRES 10 --> 10.6 migration.
            return props;
    0 讨论(0)
  • 2021-02-20 19:09

    This will work:

    Check your database schema/s and your database user privileges;

    Hibernate update mechanism may fail with this exception if there is a another database schema/user with the same table name, and the db user has the sufficient privileges to view this table.

    So in your case, the table 'YYYYYYY' may be found in more than one database user/schema, and your db user has 'DBA' privileges.

    To solve this you can either find and delete the ambiguous table or remove the user's redundant privileges.

    0 讨论(0)
  • 2021-02-20 19:09

    Use catalog value with @Table, i.e.:

    @Table(**catalog = "MY_DB_USER"**, name = "LOOKUP")
    public class Lookup implements Serializable {

    I don't have this error now. Hope this work.

    0 讨论(0)
  • 2021-02-20 19:15

    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.

    0 讨论(0)