org.postgresql.util.PSQLException:错误:关系" post"不存在

时间:2016-07-31 07:51:48

标签: postgresql spring-boot

我正在尝试创建一个弹簧启动应用程序。获取以下错误 -

org.postgresql.util.PSQLException: ERROR: relation "post" does not exist

当我尝试从eclipse运行它时。我最初得到了hibernate_sequence错误,但看了之后我看到了@GeneratedValue(strategy = GenerationType.IDENTITY)解决方案。

这是我的代码

我的帖子课程是 -

 package au.com.riosoftware.firstapp.domain;

 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;

@Entity

public class Post {
  private static final long serialVersionUID = -7049957706738879274L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
private String message;

public Post(){
}

public Post(String message){
    this.message = message;
}

public long getId() {
    return id;
}

   public String getMessage() {
     return message;
  }

   public void setMessage(String message) {
      this.message = message;
  }
 }

我的pom.xml -

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>au.com.riosoftware.firstapp</groupId>
<artifactId>firstapp</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>firstapp</name>
<url>http://maven.apache.org</url>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
<dependency>
   <groupId>org.postgresql</groupId>
   <artifactId>postgresql</artifactId>
   <version>9.4-1206-jdbc42</version>
</dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestone</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>

    <repository>
        <id>sonatype-snapshots</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-milestone</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
    <pluginRepository>
        <id>jetty</id>
        <url>http://mvnrepository.com/artifact/org.eclipse.jetty</url>
    </pluginRepository>
</pluginRepositories>

我的application.properties设置为 -

spring.jpa.database=postgresql
spring.datasource.platform=postgres
spring.jpa.show-sql=true 
spring.jpa.hibernate.ddl-auto=create-drop 
spring.database.driverClassName=org.postgresql.Driver   
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
spring.datasource.username=postgres
spring.datasource.password=postgres
server.port=8080
logging.level.org.springframework.web=DEBUG 
logging.level.org.hibernate=ERROR

知道为什么会发生这种情况

1 个答案:

答案 0 :(得分:0)

可能与区分大小写有关。

@Entity
@Table(name = "post")

此外,“post”可能是Postgres中的保留关键字,如果上述方法不起作用,请尝试更改表名。

最后一个选项是Spring没有找到实体添加

@EntityScan() -- With your base package

到你的配置。