gpt4 book ai didi

java - Spring Boot 应用程序 Heroku PostgreSQL 错误 : GenerationTarget encountered exception accepting command : Error executing DDL . .. 通过 JDBC 语句

转载 作者:行者123 更新时间:2023-12-04 08:27:59 26 4
gpt4 key购买 nike

我用 Spring Boot 创建了一个小型社交媒体应用程序,在开发中我使用了 H2 本地数据库,它运行得很好。现在我尝试将它连接到 Heroku PostgreSQL 数据库,但在标题中出现错误。任何想法为什么?
我怀疑是错误的方言,但我检查的每个地方都应该像现在一样使用 org.hibernate.dialect.PostgreSQLDialect。否则,实体或映射可能会出问题?即使是,我也无法弄清楚如何修改它们以及如何修改它们。
我对数据库的东西很陌生,所以如果这是一些愚蠢的错误,请不要判断我。
实体类:用户

package com.schabby.socialplatform.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

@Entity
@SequenceGenerator(name="seq", initialValue=1, allocationSize=100)
public class User implements Serializable {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY, generator="seq")
private Long id;

private String username;
private String password;
private String name;
private int age;
private String picture;
private boolean online;

@JsonIgnore
@OneToMany(mappedBy = "User")
private Collection<Post> posts = new ArrayList<Post>();

public User() {
}

public User(String username, String password, String name, int age, String picture, boolean online) {
this.username = username;
this.password = password;
this.name = name;
this.age = age;
this.picture = picture;
this.online = online;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public Collection<Post> getPosts() {
return posts;
}

public void setPosts(Collection<Post> posts) {
this.posts = posts;
}

public boolean isOnline() {
return online;
}

public void setOnline(boolean online) {
this.online = online;
}

public String getPicture() {
return picture;
}

public void setPicture(String picture) {
this.picture = picture;
}



}
实体类:Post
package com.schabby.socialplatform.models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;

@Entity
public class Post implements Serializable {

@Id
@GeneratedValue
private long id;

private String text;

@Temporal(javax.persistence.TemporalType.DATE)
private Date date;

@JsonIgnore
@ManyToOne
@JoinColumn(name="User_id")
private User User;


public Post() {
}

public Post(String text, Date date, User user) {
this.text = text;
this.date = date;
this.User = user;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public User getUser() {
return User;
}

public void setUser(User user) {
this.User = user;
}
}
我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.schabby</groupId>
<artifactId>socialplatform</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>socialplatform</name>
<description>Social Media Platform</description>

<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-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<type>jar</type>
</dependency>
</dependencies>

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

</project>
应用程序属性:
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

spring.datasource.url=jdbc:postgresql://ec2-54-217-206-236.eu-west-1.compute.amazonaws.com:5432/d5rk5sir0732uc?sslmode=require
spring.datasource.username=
spring.datasource.password=
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=create
谢谢你的每一个建议!

最佳答案

我在 Stackoverflow 上找到了答案!
问题是某些名称,例如我的表名:'user' 是为 PostgreSQL 保留的。因此,更改它的名称解决了我的问题。
这是原始答案:
https://stackoverflow.com/a/56206827/13304501

关于java - Spring Boot 应用程序 Heroku PostgreSQL 错误 : GenerationTarget encountered exception accepting command : Error executing DDL . .. 通过 JDBC 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65170040/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com