【发布时间】:2016-07-31 07:51:48
【问题描述】:
我正在尝试创建一个 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
知道为什么会这样
【问题讨论】: