简体   繁体   English

如何解决“Caused by: org.postgresql.util.PSQLException: ERROR: relation “employee” does not exist Position: 13”错误?

[英]How to resolve "Caused by: org.postgresql.util.PSQLException: ERROR: relation "employee" does not exist Position: 13" error?

I have tried to execute the Hibernate Demo application.我尝试执行 Hibernate 演示应用程序。 I'm getting the below error message.我收到以下错误消息。

Database: PostgreSQL Hibernate Version: 5数据库:PostgreSQL Hibernate 版本:5

Source code for Bean class package com.javatpoint; Bean的源代码 class package com.javatpoint;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
public class Employee {
@Id
private int id;
private String firstName,lastName;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}


}

Test class package com.javatpoint;测试 class package com.javatpoint;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class Test {
public static void main(String[] args) {

Configuration cfg=new Configuration();
cfg.configure("/hibernate.cfg.xml");
SessionFactory sf=cfg.buildSessionFactory();
Session session=sf.openSession();
Transaction t=session.beginTransaction();

Employee e1=new Employee();
e1.setId(1001);
e1.setFirstName("sonoo");
e1.setLastName("jaiswal");

Employee e2=new Employee();
e2.setId(1002);
e2.setFirstName("vimal");
e2.setLastName("jaiswal");

session.persist(e1);
session.persist(e2);

t.commit();
session.close();
System.out.println("successfully saved");
}
}

hibernate.cfg.xml 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">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

<session-factory>
    <property name="hbm2ddl.auto">create</property>
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="connection.url">jdbc:postgresql://localhost:5555/postgres</property>
    <property name="connection.username">postgres</property>
    <property name="connection.password">password</property>
    <property name="connection.driver_class">org.postgresql.Driver</property>

    <mapping class="com.javatpoint.Employee"/>
</session-factory>

Error Message错误信息

Jun 18, 2016 12:06:34 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.0.Final}
Jun 18, 2016 12:06:34 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jun 18, 2016 12:06:34 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jun 18, 2016 12:06:34 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Jun 18, 2016 12:06:35 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jun 18, 2016 12:06:35 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jun 18, 2016 12:06:35 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5555/postgres]
Jun 18, 2016 12:06:35 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgres, password=****}
Jun 18, 2016 12:06:35 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jun 18, 2016 12:06:35 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Jun 18, 2016 12:06:35 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
Jun 18, 2016 12:06:35 AM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Jun 18, 2016 12:06:35 AM org.hibernate.type.BasicTypeRegistry register
INFO: HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@236e3f4e
Jun 18, 2016 12:06:36 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
WARN: SQL Warning Code: 0, SQLState: 00000
Jun 18, 2016 12:06:36 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
WARN: schema "hibernatedemo" does not exist, skipping
Jun 18, 2016 12:06:36 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Unable to execute command [create table HibernateDemo.Employee (id int4 not null, firstName varchar(255), lastName varchar(255), primary key (id))]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [create table HibernateDemo.Employee (id int4 not null, firstName varchar(255), lastName varchar(255), primary key (id))]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:434)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:419)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:310)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:165)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:134)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:120)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:148)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:308)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:476)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:707)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:723)
at com.javatpoint.Test.main(Test.java:11)
Caused by: org.postgresql.util.PSQLException: ERROR: schema "hibernatedemo" does not exist
Position: 14
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:321)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:313)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:51)
... 13 more

Jun 18, 2016 12:06:36 AM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@13f17eb4'
Jun 18, 2016 12:06:36 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42P01
Jun 18, 2016 12:06:36 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERROR: relation "hibernatedemo.employee" does not exist
Position: 13
Jun 18, 2016 12:06:36 AM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
Jun 18, 2016 12:06:36 AM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1402)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:472)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3132)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2369)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:221)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
at com.javatpoint.Test.main(Test.java:28)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2934)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3434)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1396)
... 9 more
Caused by: org.postgresql.util.PSQLException: ERROR: relation "hibernatedemo.employee" does not exist
Position: 13
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:133)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
... 18 more

Eclipse Project Eclipse 项目

PostgreSQL Database PostgreSQL 数据库

Hibernate is trying to create entity in hibernatedemo schema. Hibernate 正在尝试在hibernatedemo模式中创建实体。 You need to create that schema in database.您需要在数据库中创建该架构。 I did not see your configuration that is pointing to hibernatedemo schema.我没有看到您的配置指向hibernatedemo架构。 The cfg.xml is generated by MyEclipse Hibernate tools. cfg.xml 由 MyEclipse Hibernate 工具生成。 Check that configuratioon.检查该配置。

How to create schema in PostGreSQL Link如何在 PostGreSQL Link 中创建模式

CREATE SCHEMA IF NOT EXISTS schema_name

After creating schema try again to start your application创建架构后再次尝试启动您的应用程序

You can simply add that tag to your config xml file您只需将该标签添加到您的配置 xml 文件中

  <property name="hibernate.hbm2ddl.auto">update</property>

暂无
暂无

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

相关问题 org.postgresql.util.PSQLException:错误:关系“员工”不存在 Position:13 - org.postgresql.util.PSQLException: ERROR: relation “employee” does not exist Position: 13 org.postgresql.util.PSQLException:错误:关系“ employee1”不存在 - org.postgresql.util.PSQLException: ERROR: relation “employee1” does not exist org.postgresql.util.PSQLException:错误:关系“序列”不存在 - org.postgresql.util.PSQLException: ERROR: relation “sequence” does not exist org.postgresql.util.PSQLException:错误:关系“产品”不存在 - org.postgresql.util.PSQLException: ERROR: relation "products" does not exist org.postgresql.util.PSQLException:错误:关系“用户”不存在 - SpringBoot,Hibernate,Postgresql - org.postgresql.util.PSQLException: ERROR: relation "users" does not exist - SpringBoot, Hibernate, Postgresql 由以下原因引起:org.postgresql.util.PSQLException:错误:类型“枚举”不存在 - Caused by: org.postgresql.util.PSQLException: ERROR: type “enum” does not exist 引起:org.postgresql.util.PSQLException:错误:运算符不存在:文本= integer - Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: text = integer 通过JDBC进行Postgres连接:org.postgresql.util.PSQLException:错误:关系“处方”不存在 - Postgres connectivity via JDBC: org.postgresql.util.PSQLException: ERROR: relation “prescriptions” does not exist org.postgresql.util.PSQLException:错误:关系“ bug_report_model”不存在 - org.postgresql.util.PSQLException: ERROR: relation “bug_report_model” does not exist org.postgresql.util.PSQLException:错误:关系“clienti_id_seq”不存在 - org.postgresql.util.PSQLException: ERROR: the relation“clienti_id_seq” does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM