@GeneratedValue to generate globalIndex in domainEventEntry table is getting duplicated after upgrading springboot to 3.X

Hello All,

I am using PostgreSQL database and Axon Framework for one of my spring boot applications. I have upgraded the spring boot version from 2.x to 3.1.5. I have noticed that the Hibernate version also got change to 6.X. After upgrade, The globalIndex in domainEventEntry table is getting duplicated. I start getting primary key violation exceptions while storing events in the aforementioned table as the globaIndex is already present in it.

After googling for sometime, I got to know that some changes on ID generation have been introduced in Hibernate 6.X. I presumed this could be the reason and I added a property hibernate.id.new_generator_mappings: false in my application.properties file. But there is no improvement. Any suggestions are welcome! Thanks in advance for your help!

There is a similar post (issue when upgrading to Axon 3.2 and Spring Boot 2.0) which I followed, But did not help in my case!

Pom.XML

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.5</version>
        <relativePath/>
    </parent>

    <properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <axon.version>4.8.2</axon.version>
    </properties>

DomainEventEntry.class (PreCompiled)

Sample Error:

{"@timestamp":"2024-05-29T18:06:31.388+02:00","@version":"1","message":"ERROR: duplicate key value violates unique constraint \"domain_event_entry_pkey\"\n  Detail: Key (global_index)=(502) already exists.","logger_name":"org.hibernate.engine.jdbc.spi.SqlExceptionHelper","thread_name":"global-gcp-pubsub-subscriber1","level":"ERROR","level_value":40000}

Hi @Prasanth_Antonyraj
Did you managed to solve this issue? I’m facing the same after upgrading to SpringBoot 3.x

Hi @Dalia_Daud,

Greetings!

Yes I have solved this problem. I presume you also must be using spring jpa and hibernate. In that case, you may have to add a property in your application properties file.

spring.jpa.properties.hibernate.id.db_structure_naming_strategy=legacy

You can read more about this property here https://www.baeldung.com/hibernate-sequence-naming-strategies

Adding this property helped me to resolve my issue. I hope this will solve your issue too! Best of luck! Thanks!

1 Like

Hi @Prasanth_Antonyraj

It works! Thank you!!

Hello
I try same approach .
@Entity(name = “MBX_MAILBOX_GUID”)
public class MailBoxGuid {
@Id
@Column(name = “NEXT_MAILBOX_GUID”, length = 255, nullable = false)
private String mailBoxGuid;

@Column(name = "NEXT_MAILBOX_ID", scale = 9, unique = true, nullable = false,insertable = false, updatable = false)
//@Generated(GenerationTime.ALWAYS)
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private BigInteger mailBoxId;

}
and in appication.yaml I configured below but still fail to execute
Can you please suggest me any input.
Thanks
Sumit