简体   繁体   中英

Spring JPA not creating table for an entity

In this project I have a the following entities:

  • Notification: entity for other notification entities to inherit from
  • Message

The entities that extend Notification get their tables get created but the table for Message entity doesn't.

Notification 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;
}

Message 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

application-dev.yaml - this profile IS active

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

May be read is the keyword in mysql.

https://dev.mysql.com/doc/refman/8.0/en/keywords.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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