JPA中@Table注释的用途是什么? [英] What is the use of @Table annotation in JPA?

查看:858
本文介绍了JPA中@Table注释的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这些批注的重点是要独立于数据库提供程序,而不是重新生成JAR存档.

The whole point of using these annotations is to be independent of the database provider, and not to regenerate the JAR archive.

如果我对@Table (name = myDatabase.myTableName)进行硬核,那么我首先看不到使用休眠的意义.如果确实决定切换到其他数据库提供程序,则必须修改类中的@Table (name = myDatabase.myTableName)批注,然后重新编译该应用程序.

If I hardcore the @Table (name = myDatabase.myTableName) I don't see the point of using hibernate in the first place. If I do decide to switch to a different database provider, then I will have to modify the @Table (name = myDatabase.myTableName) annotation in my class , and recompile the application .

推荐答案

@Table 注释: @Table批注允许您指定用于将实体保留在数据库中的表的详细信息.

@Table Annotation: The @Table annotation allows you to specify the details of the table that will be used to persist the entity in the database.

@Table批注提供了四个属性,使您可以覆盖表的名称,目录和架构,并对表中的列施加唯一约束.现在,我们仅使用表名称EMPLOYEE.

The @Table annotation provides four attributes, allowing you to override the name of the table, its catalogue, and its schema, and enforce unique constraints on columns in the table. For now we are using just table name which is EMPLOYEE.

@Entity
@Table(name = "EMPLOYEE")
public class Employee {
   @Id @GeneratedValue
   @Column(name = "id")
   private int id;
}

只需在此处添加表名,就不需要在Java代码中提供数据库名. http://docs.oracle.com/javaee/5/api /javax/persistence/Table.html

Just add the table name here and database name is not required to give in java code. http://docs.oracle.com/javaee/5/api/javax/persistence/Table.html

这篇关于JPA中@Table注释的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆