简体   繁体   English

在Spring应用程序中使用休眠自动创建表

[英]Create automatically table with hibernate in spring application

I have spring boot application . 我有spring boot应用程序。 I will create and update table automatically in java application but my code doesn't work. 我将在Java应用程序中自动创建和更新表,但是我的代码不起作用。

This is application.properties 这是application.properties

spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/exchange
spring.datasource.username=*****
spring.datasource.password=*****
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

This my model.I use generic class that all model use from it. 这是我的模型。我使用所有模型都使用的泛型类。

I will create table of this model . 我将创建此模型的表。

Please help me . 请帮我 。

@Getter
@Setter
@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Users extends Generic {

}

@Getter
@Setter
@MappedSuperclass
@SuppressWarnings("serial")
public class Generic implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, unique = true)
    private Long id;

    @Column(name = "createdBy")
    private Long createdBy=-1L;

    @Column(name = "updatedBy")
    private Long updatedBy=-1L;

    @Column(name = "createdDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;

    @Column(name = "updatedDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedDate;
}

我认为您忘记了应该@Table的POJO上的@Table批注,例如在Users类上添加@Table(name = "users")

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

相关问题 Hibernate 不会在 Spring 应用程序中自动创建表 - Hibernate doesn't create tables automatically in Spring application 无法使用Spring和Hibernate集成自动创建表并插入记录 - Unable to create a table automatically and insert records using spring and hibernate integration 关于在 Hibernate Java Spring 启动应用程序中自动创建表 - About auto create table in Hibernate Java Spring boot application 是否可以使 Spring Boot JPA Hibernate 应用程序自动创建具有来自 JPA 实体的必要列和关系的表? - Is it possible to make Spring Boot JPA Hibernate application to automatically create tables with necessary columns and relations from JPA entities? 我正在使用spring,hibernate和mysql。 如何让我的应用自动创建表格 - I'm using spring, hibernate and mysql. How can I let my app create the table automatically Spring MVC Hibernate应用程序加载数据库表 - Spring MVC Hibernate Application loading database table Hibernate不会创建Table - Spring MVC - Hibernate doesn't create Table - Spring MVC 在Spring和Hibernate中创建两个表之间的联接 - create join between two table in spring and hibernate Hibernate 不会在 Spring Boot 中使用 postgresql 自动创建表 - Hibernate not creating Table automatically in spring boot using postgresql 在基于Spring-Hibernate的Web应用程序中创建JAR - Create JAR out of a Spring-Hibernate based Web Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM