postgresql - 如何从 Spring Boot 应用程序正确生成 Postgres 表?
问题描述
我正在使用 spring-boot 为未来的 Angular 前端开发 RESTFUL API。我在将我的实体创建到 postgres 表中时遇到了这个问题。
检查与数据库的连接性,一切正常。使用 mvn clean install & mvn spring-boot run 命令生成正常的 tomcat 部署,没有任何错误。但是没有创建表
这是我的代码:实体:
@Entity
@Table(name = "questions")
public class Question {
@Id
@GeneratedValue(generator = "question_generator")
@SequenceGenerator(
name = "question_generator",
sequenceName = "question_sequence",
initialValue = 1000
)
private Long id;
@NotBlank
@Size(min = 3, max = 100)
private String title;
@Column(columnDefinition = "text")
private String description;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Question() {
}
}
应用程序属性:
# ===============================
# DATABASE CONNECTION
# ===============================
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
# ===============================
# JPA / HIBERNATE
# ===============================
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
# Fix Postgres JPA Error:
# Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
这是我的回购:
import model.Question;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface QuestionRepository extends JpaRepository<Question, Long> {
}
解决方案
我能够通过更改实体包并使其对应用程序可见来解决此问题。现在它工作得很好。主包名是:com.testAppBlaBla 实体的包应该是 com.testAppBlaBla.model
否则不会生成实体。
推荐阅读
- javascript - 从可重用组件传递 Route 作为道具
- uwp - Hololens 中不需要注视应用程序窗口的语音/语音识别
- javascript - 如何在 Web 项目中像 div 标签一样使用 View
- reactjs - 清除异步选择上的缓存选项
- r - R:绘制时间线流程图
- node.js - Steam OpenId 无效签名 InternalOpenIDError:
- alexa - 用于自定义技能和令牌刷新说明的 Alexa a/c 链接
- reactjs - 在 React-Router V4 中以编程方式设置路由参数最终会出现“找不到页面”
- angular - fontawesome 整合在
离子 4 - 角度 7 - google-chrome-extension - 如何在我的系统中本地设置 Metamask?