JPA - 如果没有为实体指定 @Table 怎么办?
JPA - What if @Table is not specified for the entity?
我提到了 @Table
documentation 并且它指出:
If no Table annotation is specified for an entity class, the default
values apply.
我的问题是默认值是多少?
默认table名称是实体类的非限定类名,默认模式名称是来自数据库连接的连接模式。
如果您指定 @Entity
而未指定 @Table
,您的 class 将被映射并且在数据库中您将获得 class 名称作为名称为了你的 table。
来自文档的 Marking a POJO as persistent entity 部分:
@Table is set at the class level; it allows you to define the table, catalog, and schema names for your entity mapping. If no @Table is defined the default values are used: the unqualified class name of the entity.
例如,如果您有:
@Entity
public class MyTest{ ...
您的 table 在您的数据库中将具有名称 my_test
。
请注意,PascalCase 将转换为 pascal_case。请注意这一点。
我提到了 @Table
documentation 并且它指出:
If no Table annotation is specified for an entity class, the default values apply.
我的问题是默认值是多少?
默认table名称是实体类的非限定类名,默认模式名称是来自数据库连接的连接模式。
如果您指定 @Entity
而未指定 @Table
,您的 class 将被映射并且在数据库中您将获得 class 名称作为名称为了你的 table。
来自文档的 Marking a POJO as persistent entity 部分:
@Table is set at the class level; it allows you to define the table, catalog, and schema names for your entity mapping. If no @Table is defined the default values are used: the unqualified class name of the entity.
例如,如果您有:
@Entity
public class MyTest{ ...
您的 table 在您的数据库中将具有名称 my_test
。
请注意,PascalCase 将转换为 pascal_case。请注意这一点。