简体   繁体   English

PostgreSQL的Hibernate异常,无法找到表格

[英]Hibernate exception with postgres, unable to find table

I have a table created under public schema in postgres. 我在postgres的公共架构下创建了一个表。 My hibernate.cfg.xml is: 我的hibernate.cfg.xml是:

<?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: 我的ServiceProvider.hbm.xml是:

<?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创建的查询:

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. 任何人都可以提出为什么在创建与数据库的连接后休眠状态无法在公共模式下找到service_provider表的原因。

The problem is that the table service_provider is missing or can not be found by Hibernate. 问题是表service_provider丢失或无法被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? 再次检查数据库,表service_provider是否在其中?
  2. Try to run the SQL from the dabase console 尝试从dabase控制台运行SQL
  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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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