Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Partner – Orkes – NPI EA (cat=Java)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2025 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

1. Introduction

In this tutorial, we’ll explore how to configure Hibernate 6’s implicit naming strategies for database sequences. Hibernate 6 introduces several new naming strategies that affect how sequences are named and used.

2. Standard Naming Strategy

By default, Hibernate 6 uses the standard naming strategy. It uses a standard naming convention to generate sequence names based on the entity name and the column name. For example, if we have an entity Person with a column id, the sequence name would be person_seq.

To use the standard naming strategy, we need to add the necessary configurations in application.properties for different naming strategies. Here’s how to set up the configuration for each naming strategy:

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

Let’s look at a basic Person entity class to illustrate the naming convention:

@Entity
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;
    private String name;

    // setters and getters
}

In this example, since we’re using the standard strategy, Hibernate automatically generates a sequence named person_seq alongside the table creation:

Hibernate: 
  create table person (
    id bigint not null,
    name varchar(255),
    primary key (id)
  )
Hibernate: 
  create sequence person_seq start with 1 increment by 50

One key point about the standard strategy is its default increment value. Hibernate assigns a larger value like 50 to optimize batch operations, reducing the number of database calls needed for sequence retrieval.

When we insert a Person record, Hibernate uses the person_seq sequence to generate the primary key:

Hibernate: 
  select next value for person_seq
Hibernate: 
  insert 
    into person (name,id) 
    values (?,?)

In addition, we can override the table mapping by using the @Table annotation. This allows us to specify a custom table name that is then used to generate the corresponding sequence name.

For example, if we have an entity Person with a column id, we can specify a custom table name my_person_table to generate the sequence name my_person_table_seq:

@Entity
@Table(name = "my_person_table")
public class Person {
    // ...
}

In this case, the table name is my_person_table, and the generated sequence name is my_person_table_seq:

Hibernate: 
  create table my_person_table (
    id bigint not null,
    name varchar(255),
    primary key (id)
)
Hibernate: 
  create sequence my_person_table_seq start with 1 increment by 50

When we attempt to insert a Person record, Hibernate utilizes the my_person_table_seq to generate the primary key value:

Hibernate: 
  select
    next value for my_person_table_seq

3. Legacy Naming Strategy

This strategy is similar to the standard strategy, but it uses a legacy naming convention or the generator name if specified to generate sequence names. For example, if we have an entity Person with a column id, the sequence name would be hibernate_sequence. Moreover, the hibernate_sequence sequence is used across all entities.

To enable the legacy strategy, we set the property hibernate.id.db_structure_naming_strategy to legacy in our application.properties file:

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

Let’s consider our existing Person entity class using the legacy strategy. In this scenario, Hibernate creates the table and a single sequence named hibernate_sequence with the same table name:

Hibernate: 
  create table person (
    id bigint not null,
    name varchar(255),
    primary key (id)
  )
Hibernate: 
  create sequence hibernate_sequence start with 1 increment by 1

In contrast with the standard naming strategy, when using the legacy naming strategy, the default increment value for sequences is usually 1. This means that each new value generated by the sequence will be incremented by 1. 

When inserting a Person record, Hibernate relies on hibernate_sequence to generate the primary key:

Hibernate: 
  select next value for hibernate_sequence
Hibernate: 
  insert 
    into person (name,id) 
    values (?,?)

Even with the legacy strategy, we can customize table names using the @Table annotation. In such cases, the generated sequence name won’t reflect the table name.

However, we can specify a custom sequence name by using the @SequenceGenerator annotation. This is particularly useful for managing sequences for specific entities:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_custom_seq")
@SequenceGenerator(name = "person_custom_seq", sequenceName = "person_custom_seq", allocationSize = 10)
private Long id;

In this example, we use the @SequenceGenerator annotation to specify a custom sequence name person_custom_seq with an allocation size of 10. The @GeneratedValue annotation is set to use this sequence generator:

Hibernate: 
  create table my_person_table (
    id bigint not null,
    name varchar(255),
    primary key (id)
  )
Hibernate: 
  create sequence person_custom_seq start with 1 increment by 10

When a Person record is inserted, Hibernate retrieves the next available value from the person_custom_seq sequence by executing the following SQL statement:

Hibernate: 
  select next value for person_custom_seq

The legacy strategy is primarily designed to maintain compatibility with older versions of Hibernate and to avoid breaking existing systems.

4. Single Naming Strategy

Hibernate 6 introduces the single naming strategy to simplify sequence naming by using a unified sequence name for all entities within the same schema. Similar to the legacy strategy, when using the single naming strategy, Hibernate generates a single sequence named hibernate_sequence that is shared among all entities in the schema.

This can be particularly useful for ensuring a consistent approach to sequence management. Let’s see how this works with two different entities: Person and Book.

To use the single naming strategy, we need to configure it in the application.properties file:

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

Here, we’ll create two entities, Person and Book, using the single naming strategy:

@Entity
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;
    private String title;

    // setters and getters
}

When using the single naming strategy, Hibernate generates a single sequence for all entities. Here’s how the SQL statements for the entities might look:

Hibernate: 
  create table book (
    id bigint not null,
    title varchar(255),
    primary key (id)
  )
Hibernate: 
  create table person (
    id bigint not null,
    name varchar(255),
    primary key (id)
  )
Hibernate: 
  create sequence hibernate_sequence start with 1 increment by 1

Here we see only one sequence hibernate_sequence is created. Therefore, when inserting records into the Person and Book tables, Hibernate uses the hibernate_sequence sequence to generate the primary key values:

Person person = new Person();
person.setName("John Doe");
personRepository.save(person);

Book book = new Book();
book.setTitle("Baeldung");
bookRepository.save(book);

List<Person> personList = personRepository.findAll();
List<Book> bookList = bookRepository.findAll();

assertEquals((long)1,(long) personList.get(0).getId());
assertEquals((long)2, (long) bookList.get(0).getId());

In this example, we create and save two entities: Person and Book. Both entities should use the same sequence generator to generate primary keys. When we save the Person first and then the Book, the Person should get ID 1, and the Book should get ID 2.

5. Custom Naming Strategy

Moreover, we can also define our own sequence naming conventions through custom naming strategies. To use a custom naming strategy for sequences, we first need to create a custom implementation of ImplicitDatabaseObjectNamingStrategy. This interface is used to provide custom naming strategies for various database objects, including sequences.

Here’s how we can create a custom implementation of ImplicitDatabaseObjectNamingStrategy to customize sequence names:

public class CustomSequenceNamingStrategy implements ImplicitDatabaseObjectNamingStrategy {
    @Override
    public QualifiedName determineSequenceName(Identifier catalogName, Identifier schemaName, Map<?, ?> map, ServiceRegistry serviceRegistry) {
        JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class);
        String seqName = ((String) map.get("jpa_entity_name")).concat("_custom_seq");
        return new QualifiedSequenceName(
          catalogName,
          schemaName,
          jdbcEnvironment.getIdentifierHelper().toIdentifier(seqName));
    }

    // others methods
}

In the determineSequenceName() method, we customize the generation of sequence names. First, we use the JdbcEnvironment service to access various database-related utilities, which helps us manage database object names efficiently. We then create a custom sequence name by appending a _custom_seq suffix to the entity name. This approach allows us to control the sequence name format across our database schema.

Next, we need to configure Hibernate to use our custom naming strategy:

spring.jpa.properties.hibernate.id.db_structure_naming_strategy=com.baeldung.sequencenaming.CustomSequenceNamingStrategy

With the custom ImplicitDatabaseObjectNamingStrategy, Hibernate generates SQL statements with the custom sequence names we defined:

Hibernate: 
  create table person (
    id bigint not null,
    name varchar(255),
    primary key (id)
  )
Hibernate: 
  create sequence person_custom_seq start with 1 increment by 50

In addition to ImplicitDatabaseObjectNamingStrategy, we can use PhysicalNamingStrategy which defines comprehensive naming conventions across all database objects. With PhysicalNamingStrategy, we’re able to implement complex naming rules that apply not just to sequences but to other database objects as well.

Here’s an example of how to implement custom sequence naming using PhysicalNamingStrategy:

public class CustomPhysicalNamingStrategy extends DelegatingPhysicalNamingStrategy {
    @Override
    public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment context) {
        return new Identifier(name.getText() + "_custom_seq", name.isQuoted());
    }

    // other methods for tables and columns
}

6. Conclusion

In this article, we’ve explored how to use a custom naming strategy in Hibernate 6. The standard strategy generates sequence names based on entity names, while legacy and single strategies simplify sequence management by using a unified sequence name. Additionally, the custom naming strategy allows us to tailor sequence naming conventions.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2025 – NPI (All)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)