我在postgres中的公共模式下创建了一个表。 我的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>
我的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>
在日志中我看到:
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)
在上面的日志中,以下是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=?
任何人都可以建议为什么hibernate在创建与DB的连接后无法在公共模式下找到service_provider表。
答案 0 :(得分:1)
问题是表service_provider丢失或者Hibernate找不到。
以下是一些找出问题的方法:
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE';