Spring JPA 没有为实体创建 table
Spring JPA not creating table for an entity
在这个项目中,我有以下实体:
- Notification:供其他通知实体继承的实体
- 留言
扩展 Notification 的实体会创建它们的 table,但 Message 实体的 table 不会。
通知class:
@Data
@Entity
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Notification {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
protected long id;
// ... attributes
@OneToMany(mappedBy = "notification")
protected List<Message> messages;
}
留言class:
@Data
@Entity
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
public class Message {
@Id
@GeneratedValue
private long id;
// ... attributes
@JsonIgnore
@ManyToOne
private Notification notification;
private boolean read;
}
application.yaml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
jpa:
hibernate:
naming:
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
use-new-id-generator-mappings: true
应用程序-dev.yaml - 此配置文件处于活动状态
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3308/db
username: dev
password: dev
jpa:
hibernate:
ddl-auto: create
show-sql: true
generate-ddl: true
可能是read是mysql中的关键字。
在这个项目中,我有以下实体:
- Notification:供其他通知实体继承的实体
- 留言
扩展 Notification 的实体会创建它们的 table,但 Message 实体的 table 不会。
通知class:
@Data
@Entity
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Notification {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
protected long id;
// ... attributes
@OneToMany(mappedBy = "notification")
protected List<Message> messages;
}
留言class:
@Data
@Entity
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
public class Message {
@Id
@GeneratedValue
private long id;
// ... attributes
@JsonIgnore
@ManyToOne
private Notification notification;
private boolean read;
}
application.yaml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
jpa:
hibernate:
naming:
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
use-new-id-generator-mappings: true
应用程序-dev.yaml - 此配置文件处于活动状态
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3308/db
username: dev
password: dev
jpa:
hibernate:
ddl-auto: create
show-sql: true
generate-ddl: true
可能是read是mysql中的关键字。