4

I'm getting this error when building my JHipster application:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'. Found [1] and [50]

I see the 50 here, but I don't know where the 1 is coming from.

Since the last time it worked, I have added a few new entities defined in these Kotlin files.

I'm working on adding the Thinkster conduit demo as one feature into my application. On its own the demo builds and runs without any problems. To get where I am now, I copied the code from the demo into my app and adjusted a few things, mostly related to the User entity. Since JHipster doesn't let you add fields to User, I created an Author entity with a 1:1 relationship to it. That in itself probably doesn't have anything to do with this error. I figure that something in this new code must be trying to create a sequence and the default increment size is one.

4 Answers 4

4

You're probably missing a few tags that are required since JHipster makes a lot of assumptions about project setup. This is what was necessary to get my project working:

@Entity
@Table(name = "tags")
public class Tag {
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
  @SequenceGenerator(name = "sequenceGenerator")
  private int id;
}

Standard hibernate would let you get away without specifying the strategy or generator, but since it was configured already you need to match.

Sign up to request clarification or add additional context in comments.

Comments

2

The problem is your sequence generator annotation does not have sequenceName specified so it uses common hibernate_sequence sequence in database. The sequence has its increment and you apparently try to specify a different.

So even if you specified the sequence generator for your table, it is actually shared with your other generators and "1" is from this hibernate_sequence.

Just try to name your sequence so it has its own entity in the database and you should be OK with any increment size.

Comments

1

I had the same problem, some entities had :

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

while some other entities had :

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    private Long id;

I changed all the entities in the project to the first type i.e. AUTO and got rid of my abstract class DomainEntityBase which had the @Id and this solved the issue. P.S. I'm using jhipster.

Comments

0

Create a new sequence in your DB using a name different from "hibernate_sequence", then use that sequence in your @SequenceGenerator and also specify the name of the schema the sequence was created under. Example, if you have defined your schema this way:

CREATE SEQUENCE wallet.wallet_sequence
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;

Then your entity annotation should be as follows:

@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hibernate_seq") @SequenceGenerator(name = "hibernate_seq", sequenceName = "wallet_sequence", schema = "wallet")

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.