In my Spring Boot project I am opening access to an external database, where some tables are already defined.
I want to add some new @Entity classes and auto-update schema.
@Entity
@Table(name = "email")
public class Email {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name="email")
private String email;
}
So I define a property for that in my application.properties file:
spring.jpa.hibernate.ddl-auto=update
But how can I prevent updating the schema, when I add a field to @Entity class (e.g. accidentally), that maps "old" tables, which I must not change.
CodePudding user response:
It is not possible to configure schema generation behavior at entity level.
To have better control over database schema evolution, it is recommended to use flyway or liquibase instead of relying on hibernate schema generation.