Javax persistence change IDENTITY to SEQUENCE on production level

820 Views Asked by At

Is it possible to change id generation from GenerationType.IDENTITY to GenerationType.SEQUENCE without pain for a production version of a service? DBMS is PostgreSQL.

I need to switch to SEQUENCE in order to allow Hibernate execute batch operations. But my production service had a IDENTITY strategy for about one year. Will the change in Entity class somehow affect the previously generated IDs?

Now I have

@Entity 
@EqualsAndHashCode(of = {"id"}, callSuper = false)
public class MyClass {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Getter @Setter
    private Long id;

}

What will happen if I will change the strategy to GenerationType.SEQUENCE?

1

There are 1 best solutions below

0
On BEST ANSWER

A change to GenerationType.SEQUENCE should not be an issue as long as you make sure that the sequence starts at a value that's higher than any existing value in the id column.