繁体   English   中英

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

[英]Create automatically table with hibernate in spring application

我有spring boot应用程序。 我将在Java应用程序中自动创建和更新表,但是我的代码不起作用。

这是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

这是我的模型。我使用所有模型都使用的泛型类。

我将创建此模型的表。

请帮我 。

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM