renanvm
renanvm

Reputation: 216

Alternative initial value for entity in JPA

I have the following entity and their mapping

@Entity
@Table(name = "test")
public class Test implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator", initialValue = 20000)

I want id value begins in 20000 but it doesn't work in postgresql. When the application starts I receive this exception

Caused by: org.hibernate.HibernateException: Multiple references to database sequence [sequence_generator] were encountered attempting to set conflicting values for 'initial value'. Fou nd [20000] and [1]

Do I need a extra configuration to it works?

PS: It is a new database without any previous configuration

Upvotes: 0

Views: 136

Answers (1)

Furkan Alnıak
Furkan Alnıak

Reputation: 78

You could try @TableGenerator annotation. Initial values can be set and seed other values. You can find example and documentation here: Set Initial Value Of Table Generator

Upvotes: 1

Related Questions