简体   繁体   中英

Hibernate exception with postgres, unable to find table

I have a table created under public schema in postgres. My hibernate.cfg.xml is:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection_pool_size">10</property>
        <property name="connection.autocommit">true</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
        <property name="show_sql">true</property>
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://10.65.182.239:5432/DB</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">postgres</property>
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">none</property>
        <mapping resource="com/cisco/snowball/ServiceProvider.hbm.xml"></mapping>
    </session-factory>


</hibernate-configuration>

My ServiceProvider.hbm.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.cisco.snowball.hibernate">
  <class name="ServiceProvider" table="SERVICE_PROVIDER" schema="public">
    <id name="id" column="id">
      <generator class="increment" />
    </id>
    <property name="name" column="name" />
    <property name="status" column="status" />
    <property name="revision" column="revision" />
    <property name="createdOn" column="createdOn" />
    <property name="createdBy" column="createdBy" />
    <property name="modifiedOn" column="modifiedOn" />
    <property name="modifiedBy" column="modifiedBy" />
    <property name="description" column="description" />
    <property name="tags" column="tags" />
    <property name="accountNumber" column="accountNumber" />
    <property name="address" column="address" />
    <property name="billingDetails" column="billingDetails" />
    <property name="contactDetails" column="contactDetails" />
    <property name="adminDetails" column="adminDetails" />
    <property name="connectionDetails" column="connectionDetails" />
  </class>
</hibernate-mapping>

In the logs I see:

INFO: HHH000046: Connection properties: {user=postgres, password=****, pool_size=10, autocommit=true}
Jul 01, 2014 2:57:05 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Jul 01, 2014 2:57:05 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Jul 01, 2014 2:57:05 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Jul 01, 2014 2:57:05 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select servicepro0_.id as id0_0_, servicepro0_.name as name0_0_, servicepro0_.status as status0_0_, servicepro0_.revision as revision0_0_, servicepro0_.createdOn as createdOn0_0_, servicepro0_.createdBy as createdBy0_0_, servicepro0_.modifiedOn as modifiedOn0_0_, servicepro0_.modifiedBy as modifiedBy0_0_, servicepro0_.description as descript9_0_0_, servicepro0_.tags as tags0_0_, servicepro0_.accountNumber as account11_0_0_, servicepro0_.address as address0_0_, servicepro0_.billingDetails as billing13_0_0_, servicepro0_.contactDetails as contact14_0_0_, servicepro0_.adminDetails as adminDe15_0_0_, servicepro0_.connectionDetails as connect16_0_0_ from public.SERVICE_PROVIDER servicepro0_ where servicepro0_.id=?
Jul 01, 2014 2:57:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42P01
Jul 01, 2014 2:57:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERROR: relation "public.service_provider" does not exist
  Position: 659
Jul 01, 2014 2:57:06 PM org.hibernate.event.internal.DefaultLoadEventListener onLoad
INFO: HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: ERROR: relation "public.service_provider" does not exist
  Position: 659
Exception in thread "main" org.hibernate.exception.SQLGrammarException: ERROR: relation "public.service_provider" does not exist
  Position: 659
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)

In the above log, following is the query created by hibernate:

Hibernate: select servicepro0_.id as id0_0_, servicepro0_.name as name0_0_, servicepro0_.status as status0_0_, servicepro0_.revision as revision0_0_, servicepro0_.createdOn as createdOn0_0_, servicepro0_.createdBy as createdBy0_0_, servicepro0_.modifiedOn as modifiedOn0_0_, servicepro0_.modifiedBy as modifiedBy0_0_, servicepro0_.description as descript9_0_0_, servicepro0_.tags as tags0_0_, servicepro0_.accountNumber as account11_0_0_, servicepro0_.address as address0_0_, servicepro0_.billingDetails as billing13_0_0_, servicepro0_.contactDetails as contact14_0_0_, servicepro0_.adminDetails as adminDe15_0_0_, servicepro0_.connectionDetails as connect16_0_0_ from public.SERVICE_PROVIDER servicepro0_ where servicepro0_.id=?

Can anybody pls suggest why hibernate is unable to find the service_provider table under public schema after creating a connection to the DB.

The problem is that the table service_provider is missing or can not be found by Hibernate.

Here are a couple of ways to find out what is the matter:

  1. Check the database again, is the table service_provider in there?
  2. Try to run the SQL from the dabase console
  3. List the tables in the database to really make sure that the table is there, this avoids any caches etc.
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM