My springboot trys to create a table that already exists in my mysql db
When I start springboot, it throws an exception
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table credential
Caused by: java.sql.SQLSyntaxErrorException: Table 'credential' already exists
Now I have an entity called credential
@Entity
@Table(name="credential")
public class CredentialEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
What I think is happening is that springboot sees the entity and try to create that table and throws an exception because the table already exists.
Is there a way to set something on the entity to stop springboot trying to create the table.
CodePudding user response:
JPA does have that feature to auto create tables, after scanning your entity classes. According to the spring doc, the feature is controlled with the properties spring.jpa.generate-ddl(boolean) and spring.jpa.hibernate.ddl-auto(hibernate specific). Setting the first to false should stop table generation on startup.
CodePudding user response:
Thank you everyone In my application.properties file I had the following line spring.jpa.hibernate.ddl-auto=update.
I removed this and now springboot starts up without trying to create a new table per entity.
