1

I have a problem for create a sequence in PostgreSQL, I use a SpringBoot/Hibernate/JPA for this issue, When the application will create tables and sequences, Hibernate don´t use the schema property for @SequenceGenerator.

   @Entity
   @Table(schema=Schemas.ADMIN, name="tbl_client")
   public class Client implements CommonsEntity<Integer>{

   private static final long serialVersionUID = 1L;

   static final String SQ_CLIENT = "sq_client";

   @Id
   @Column(name="id_client")
   @GeneratedValue(generator=Client.SQ_CLIENT, strategy=GenerationType.AUTO)
   @SequenceGenerator(schema=Schemas.ADMIN, name=Client.SQ_CLIENT    sequenceName=Client.SQ_CLIENT, initialValue=1, allocationSize=1)
   private Integer id;

The sequence created in Postgre is: create sequence sq_client

I use SpringBoot 1.3.5 and Hibernate 4.3.11.

Thanks.

1
  • I resolved using Hibernate version 5 and SpringBoot 1.4.X. Commented Dec 13, 2016 at 14:24

1 Answer 1

3

I think you are using incorrect strategy for GeneratedValue.

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SQ_CLIENT)
  @SequenceGenerator(name = SQ_CLIENT, sequenceName = SQ_CLIENT,
      allocationSize = 1,initialValue=1)
  private long id;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.