Spring Boot JPA底层是用Hibernate实现的,默认情况下,数据库表格的名字是相应的class名字的首字母大写。命名的定义是通过接口ImplicitNamingStrategy来定义的:
/** * Determine the implicit name of an entity's primary table. * * @param source The source information * * @return The implicit table name. */publicIdentifierdeterminePrimaryTableName(ImplicitEntityNameSource source);
我们看下它的实现ImplicitNamingStrategyJpaCompliantImpl:
@OverridepublicIdentifierdeterminePrimaryTableName(ImplicitEntityNameSource source) {if ( source ==null ) {// should never happen, but to be defensive...thrownewHibernateException( "Entity naming information was not provided." ); }String tableName =transformEntityName( source.getEntityNaming() );if ( tableName ==null ) {// todo : add info to error message - but how to know what to write since we failed to interpret the naming sourcethrownewHibernateException( "Could not determine primary table name for entity" ); }returntoIdentifier( tableName,source.getBuildingContext() ); }