Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the JPA @Table annotation "catalog" and "schema" variables used for?

Tags:

Why are these important, what effect do they have on the database at hand?

Isn't the "schema" already decided at that point, as it exists in the database?

What exactly is a "catalog"? What kind of variable/input is the JPA catalog field expecting? Also, same question for the "schema" field.

like image 339
Sam Levin Avatar asked Jun 25 '12 05:06

Sam Levin


People also ask

What is the use of @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. The @Table annotation provides four attributes, allowing you to override the name of the table, its catalog, and its schema, and enforce unique constraints on columns in the table.

What is catalog JPA?

Catalogs and schemas are "namespaces" that you define on the server side of the database. Some databases contains schemas, some contains catalogs, and some contains both.

What annotation we are using for JPA?

The JPA specification requires the @Entity annotation. It identifies a class as an entity class. You can use the name attribute of the @Entity annotation to define the name of the entity. It has to be unique for the persistence unit, and you use it to reference the entity in your JPQL queries.

What is the use of @entity annotation in hibernate?

@Entity annotation marks this class as an entity. @Table annotation specifies the table name where data of this entity is to be persisted. If you don't use @Table annotation, hibernate will use the class name as the table name by default.


1 Answers

Catalogs and schemas are "namespaces" that you define on the server side of the database. Some databases contains schemas, some contains catalogs, and some contains both. When logging in with a specific user, some databases defaults the schema/catalog to the user's namespace, causing the table to not be visible to other users, thus, causing the need to use a "common" namespace. So, depending on the database you are using to back your data, you might want to ignore those settings.

For MySQL, you might want to ignore those settings. This is because the "database" part of the JDBC URL (the one after the last slash) points to the database name, which is semantically identical to schema (for MySQL).

like image 180
jpkrohling Avatar answered Sep 28 '22 00:09

jpkrohling