Partner – JPA Buddy – NPI (tag=JPA/Hibernate)
announcement - icon

The right tools can and will save a lot of time. As long as you are using Hibernate and IntelliJ IDEA you can boost your coding speed and quality with JPA Buddy. It will help in a lot of the day-to-day work:

  • Creating JPA entities that follow best practices for efficient mapping
  • Creating DTOs from entities and MapStruct mappers using convenient visual tools
  • Generating entities from the existing database or Swagger-generated POJOs
  • Visually composing methods for Spring Data JPA repositories
  • Generating differential SQL to update your schema in accordance with your changes in entities
  • Autogenerating Flyway migrations and Liquibase changelogs comparing entities with the database or two databases
  • … and a lot more

Simply put, you'll learn and use the best practices of Hibernate and surrounding technology and become a lot more!

Definitely visit the JPA Buddy site to see its features in action closer.

Partner – DBSchema – NPI (tag=SQL)
announcement - icon

DbSchema is a super-flexible database designer, which can take you from designing the DB with your team all the way to safely deploying the schema.

The way it does all of that is by using a design model, a database-independent image of the schema, which can be shared in a team using GIT and compared or deployed on to any database.

And, of course, it can be heavily visual, allowing you to interact with the database using diagrams, visually compose queries, explore the data, generate random data, import data or build HTML5 database reports.

>> Take a look at DBSchema

Course – LSD (cat=Persistence)

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


1. Introduction

In this short tutorial, we'll learn how to set SQL table names using JPA.

We'll cover how JPA generates the default names and how to provide custom ones.

2. Default Table Names

The JPA default table name generation is specific to its implementation.

For instance, in Hibernate the default table name is the name of the class with the first letter capitalized. It's determined through the ImplicitNamingStrategy contract.

But we can change this behavior by implementing a PhysicalNamingStrategy interface.

3. Using @Table

The easiest way to set a custom SQL table name is to annotate the entity with @javax.persistence.Table and define its name parameter:

@Table(name = "ARTICLES")
public class Article {
    // ...

We can also store the table name in a static final variable:

@Table(name = Article.TABLE_NAME)
public class Article {
    public static final String TABLE_NAME= "ARTICLES";
    // ...

4. Overwriting the Table Name in JPQL Queries

By default in JPQL queries, we use the entity class name:

select * from Article

But we can change it by defining the name parameter in the @javax.persistence.Entity annotation:

@Entity(name = "MyArticle")

Then we'd change our JPQL query to:

select * from MyArticle

5. Conclusion

In this article, we've learned how JPA generates default table names and how to set SQL table names using JPA.

As always all source code is available over on GitHub.

Course – LSD (cat=Persistence)

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

res – Persistence (eBook) (cat=Persistence)
Comments are closed on this article!