[英]Why @Table annotation is optional in CRUD operation through spring
I am new to spring and spring-boot and while learning Spring CRUD I was going through different articles and I saw these lines. 我是spring和spring-boot的新手,在学习Spring CRUD时,我正在阅读不同的文章,并且看到了这些内容。
"And why @Entity annotation is mandatory? … well, it is the way how JPA is designed. When you create a new entity you have to do at least two things annotated it with @Entity create an id field and annotate it with @Id Anything else is optional, for example, the table name is derived from entity class name (and therefore @Table annotation can be optional), table's columns are derived from entities variables (and therefore @Column annotation can be optional), and so on …"
“为什么@Entity注释是强制性的?…嗯,这就是JPA的设计方式。创建新实体时,您至少必须做两件事,即用@Entity对其进行注释,创建一个id字段,并使用@Id对其进行注释。其他任何东西都是可选的,例如,表名是从实体类名派生的(因此@Table批注可以是可选的),表的列是从实体变量派生的(因此@Column批注可以是可选的),依此类推…… “
So my question is how spring will bifurcate the tables and their column names if we do not provide @Table
annotation and @Column
annotations. 所以我的问题是,如果不提供
@Table
注释和@Column
注释,spring将如何对表及其列名称进行分叉。
As you asked your question in the context of Spring Boot. 正如您在Spring Boot上下文中提出的问题。 There are two options that determine the naming strategy:
有两个选项可以确定命名策略:
spring.jpa.hibernate.naming.implicit-strategy
spring.jpa.hibernate.naming.implicit策略
This option is used to determine the names when we don't provide the table and column names explicitly in the entity definition 当我们在实体定义中未明确提供表名和列名时,此选项用于确定名称
Usually this defaults to: ImplicitNamingStrategyJpaCompliantImpl
通常,此默认值为:
ImplicitNamingStrategyJpaCompliantImpl
More implementations . 更多实现 。
spring.jpa.hibernate.naming.physical-strategy
spring.jpa.hibernate.naming.physical策略
This is more customizable, pluggable strategy contract for applying physical naming rules for database object names. 这是更可定制的,可插入的策略合同,用于为数据库对象名称应用物理命名规则。
By default, a SpringPhysicalNamingStrategy
is used where all dots camel casing is replaced by underscores. 默认情况下,使用
SpringPhysicalNamingStrategy
,其中所有点的驼峰式外壳均由下划线替换。 Also, table names are generated in the lower case. 另外,表名以小写形式生成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.