Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'. Found [50] and [1]

2,437 views
Skip to first unread message

Shraddha Mahajan

unread,
Mar 11, 2018, 3:16:37 PM3/11/18
to Axon Framework Users
Hi,

i am using Axon 3.1.3 spring-boot-starter. however when i start app i am getting error but if i removed axon discrepancies then app works fine. 

my database configuration:

datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:payments;DB_CLOSE_DELAY=-1
username: payments
password:
h2:
console:
enabled: true
jpa:
database-platform: io.github.jhipster.domain.util.FixedH2Dialect
database: H2
show-sql: true
properties:
hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate:
      ddl-auto: update

When i run sprint-boot application, i am getting following error:

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 [50] and [1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at com.amex.aet.fxip.service.payment.PaymentsApp.main(PaymentsApp.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.hibernate.HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'.  Found [50] and [1]
at org.hibernate.boot.model.relational.Sequence.validate(Sequence.java:79)
at org.hibernate.id.enhanced.SequenceStructure.registerExportables(SequenceStructure.java:153)
at org.hibernate.id.enhanced.SequenceStyleGenerator.registerExportables(SequenceStyleGenerator.java:452)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.handleIdentifierValueBinding(InFlightMetadataCollectorImpl.java:2275)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processExportableProducers(InFlightMetadataCollectorImpl.java:2231)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.buildMetadataInstance(InFlightMetadataCollectorImpl.java:2194)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:305)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:360)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:382)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:371)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 19 common frames omitted


i have one entity, using sequence:

@Entity
@Table(name = "payment")
public class Payment implements Serializable {

private static final long serialVersionUID = 1L;

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

Steven van Beelen

unread,
Mar 14, 2018, 9:35:35 AM3/14/18
to axonfr...@googlegroups.com
Hi Shraddha,

Axon Framework internally also uses the `@GeneratedValue` annotation to generate the `global index` for the events created.
I assume that the same sequence is used for the `global index`, as is for your `Payment` view.
Additionally, I guess that you're using all of Axons defaults, which means that the same transaction to store the event is used to store your `Payment` view.
I'm not sure about this, but maybe your settings do not allow that sequence to be incremented twice in the same transaction?
Like I just said, I'm not a 100% sure about this, so any other input would be valuable for this.

Cheers,
Steven

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Allard Buijze

unread,
Mar 16, 2018, 9:19:14 AM3/16/18
to axonfr...@googlegroups.com
Hi Shraddha,

you can override the default behavior of Axon's DomainEventEntry class' Sequence Generator by creating a META-INF/orm.xml file with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="2.0">
<mapped-superclass class="org.axonframework.eventsourcing.eventstore.AbstractSequencedDomainEventEntry" access="FIELD">
<attributes>
<id name="globalIndex">
<generated-value generator="domainEventGenerator" strategy="SEQUENCE"/>
</id>
</attributes>
</mapped-superclass>
<entity class="org.axonframework.eventsourcing.eventstore.jpa.DomainEventEntry" access="FIELD">
<sequence-generator name="domainEventGenerator" sequence-name="domain_event_seq" allocation-size="1"/>
</entity>
</entity-mappings>

In the "sequence-generator" field, you can pass in the configuration of the sequence you'd want to use. We recommend creating a dedicated sequence for the DomainEventEntry with an allocation-size of 1, to reduce the chance of "gaps" in these sequences.

Kind regards,

Allard Buijze
--
Allard Buijze
CTO

E: allard...@axoniq.io
T: +31 6 34 73 99 89

Wayne Stidolph

unread,
Dec 7, 2018, 8:47:27 PM12/7/18
to Axon Framework Users
With Axon 4.0.3 and JHipster 5.7.0 this solution didn't work, but Allard emailed me that:

if you change “org.axonframework.eventsourcing.eventstore.AbstractSequencedDomainEventEntry" to “org.axonframework.eventhandling. AbstractSequencedDomainEventEntry”, it should work.
 
There is one other class that uses a SequenceGenerator:
“org.axonframework.modelling.saga.repository.jpa.AssociationValueEntry”
 
The field declaring the generator is “id”. You might have to change the orm.xml to change that one as well. 

So, I tried (see below for my META-INF/orm.xml).  I may have done it wrong, I haven't looked at JPA mappings in a long, long, time ...
 but at least it starts up; thanks, Allard!

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="2.0">
    <mapped-superclass class="org.axonframework.eventhandling.AbstractSequencedDomainEventEntry" access="FIELD">
        <attributes>
<id name="globalIndex">
<generated-value generator="domainEventGenerator" strategy="SEQUENCE"/>
</id>
</attributes>
</mapped-superclass>
<entity class="org.axonframework.eventsourcing.eventstore.jpa.DomainEventEntry" access="FIELD">
<sequence-generator name="domainEventGenerator" sequence-name="domain_event_seq" allocation-size="1"/>
</entity>
    <entity class="org.axonframework.modelling.saga.repository.jpa.AssociationValueEntry" access="FIELD">
<sequence-generator name="assocValueEntryGenerator" sequence-name="assoc_entry_seq" allocation-size="1"/>
<attributes>
<id name="id">
<generated-value generator="assocValueEntryGenerator" strategy="SEQUENCE"/>
</id>
</attributes>
</entity>
</entity-mappings>
Reply all
Reply to author
Forward
0 new messages