Name attribute in @Entity and @Table

后端 未结 4 1900
一向
一向 2020-12-01 02:30

I have a doubt, because name attribute is there in both @Entity and @Table

For example, I\'m allowed to have same value for name attribute

@Entity(n         


        
4条回答
  •  情话喂你
    2020-12-01 02:55

    @Entity(name = "someThing") => this name will be used to name the Entity
    @Table(name = "someThing")  => this name will be used to name a table in DB
    

    So, in the first case your table and entity will have the same name, that will allow you to access your table with the same name as the entity while writing HQL or JPQL.

    And in second case while writing queries you have to use the name given in @Entity and the name given in @Table will be used to name the table in the DB.

    So in HQL your someThing will refer to otherThing in the DB.

提交回复
热议问题