1
  • MySQL Version = 5.5.51
  • SpringBoot Version = 1.2.8.RELEASE
  • mysql-connector-java = 5.1.36

Given:

I have an entity which has an index on a column(deliveryIndicator) whose data type is "bit NOT NULL DEFAULT 0".

I have set ddl-auto to update in my application.properties like this:

        spring.jpa.hibernate.ddl-auto = update

When

When I ran my application

Then

JPA reset the all the data for the deliveryIndicator column to 0.

Note: other index column data are not resetting.

My entity is defined like this

    @Entity
    @Table(name = "Office",
            indexes = {@Index(name = "geo_index", columnList = "latitude,longitude"),
            @Index(name = "deliveryIndicator", columnList = "deliveryIndicator")})
    public class Office {

        @Id
        @Column(name = "id")
        private long id;

        @Column(name = "longitude")
        private Double longitude;

        @Column(name = "latitude")
        private Double latitude;

        @Column(name = "parkingIndicator", columnDefinition = "bit NOT NULL DEFAULT 0")
        private boolean parkingIndicator;

        @Column(name = "disabilityIndicator", columnDefinition = "bit NOT NULL DEFAULT 0")
        private boolean disabilityIndicator;

        @Column(name = "deliveryIndicator", columnDefinition = "bit NOT NULL DEFAULT 0")
        private boolean deliveryIndicator;
        }

Now, I have tried following to fix it:

Removed the index on deliveryIndicator.

    @Entity
    @Table(name = "Office",
            indexes = {@Index(name = "geo_index", columnList = "latitude,longitude")})
    public class Office {....}

After this when I ran the application (after bringing back the DB to the previous state) the deliveryIndicator column data was not effected/resetted.

My query is :

  • Why this is happening.
  • Is there any other solution for this.
sanjaykumar81
  • 435
  • 1
  • 6
  • 13

0 Answers0