@Entity和@Table中的名称属性 [英] name attribute in @Entity and @Table
问题描述
我有一个怀疑的名称属性是在这两个
@Entity和@Table
blockquote>
例如我可以为name属性赋予相同的值
@ Entity(name =someThing)
@Table(name =someThing)
而且我可以为同一个班级设置不同的名字
@Entity(name =someThing)
@Table (name =otherThing)
有人可以告诉我这两者之间有什么区别,
解决方案
@Entity( name =someThing)=>这个名字将被用来命名实体
@Table(name =someThing)=>这个名字将用于命名DB
中的表格第一种情况是你的表和实体具有相同的名称,这将允许你在编写HQL或JPQL时访问与实体同名的表。
编写查询时,必须使用 @Entity 中给出的名称和 @Table 中给出的名称来命名DB中的表。
所以在HQL中, someThing 将引用DB中的 otherThing
I have a doubt name attribute is there in both
@Entity and @Table
for example I am allowed to have same value for name attribute
@Entity(name = "someThing") @Table(name = "someThing")
and I can have different names as well for same class
@Entity(name = "someThing") @Table(name = "otherThing")
can anybody tell me what is the difference between these two and why we have same attribute in both ?
解决方案@Entity(name = "someThing") => this name will be used to name Entity @Table(name = "someThing") => this name will be used to name a table in DB
So in first case your table and entity will have same name, that will allow you to access your table with same name as entity while writing HQL or JPQL.
And in second case while writing queries you have to use the name given in @Entity and name given in @Table will be used to name the table in DB.
so in HQL your someThing will refer to otherThing in DB
这篇关于@Entity和@Table中的名称属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!