top of page

Mapping Entity Class Names to SQL Table Names with JPA

Introduction:

  • Creating JPA entities that follow best practices for efficient mapping.

  • Creating DTOs from entities and Map Struct mappers using convenient visual tools.

  • Generating differential SQL to update your schema in accordance with your changes in entities.

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.

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:


@Entity

@Table(name = "ARTICLES")

public class Article {

}


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


@Entity

@Table(name = Article.TABLE_NAME)

public class Article {

public static final String TABLE_NAME= "ARTICLES";

}


Conclusion:


@Table annotation allows you to specify the details of the table that will be used to persist the entity in the database.


 
 
 

Recent Posts

See All

Comments


MiIT Logo

Company

Contact Us

905-487-4880 

5160 Explorer Dr #34, Mississauga,ON L4W 4T7

646-713-5711

4466 Buttonwood Ln Lilburn, GA 30047

262 Chapman Rd, STE 240 Newark DE 19702

Stay up to date on the latest from MiIT

  • Instagram
  • Facebook
  • http://linkedin.com/company/miittechnologies/about/
  • Whatsapp

© All Content MiIT Technologies Inc.2019 - 2024. All rights reserved.

bottom of page