0

I downloaded empty proj from spring initializr with web,jpa and postgres dependencies.

Added this config in application.properties

spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update

and created class Test, that's all I have.

    @Entity
    @Table(name = "tests")
    public class Test {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long id;

        @Column(length = 200)
        private String author;
    }
}

And then when the column's length parameter changes nothing happens in the database.

I tried to delete some columns and change some other parameters, result zero "alter table" SQL statements.

Update works only if new column added( update works only on this concrete new column only once).

airush
  • 722
  • 9
  • 19

1 Answers1

1

from how does exactly spring.jpa.hibernate.ddl-auto property works in Spring?

The update operation for example will attempt to add new columns, constraints, etc but will never remove a column or constraint that may have existed previously but no longer does as part of the object model from a prior run.

if you want to change length after table is created, you have to use a Higher-level Database Migration Tool like flyway or liquibase.

Devilluminati
  • 328
  • 1
  • 15