[英]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.