How to extend the JPA annotation to better support or Mapping

Source: Internet
Author: User
Tags extend new features relational database table

Introduction to JPA and OpenJPA

With the application of object-oriented data model, the mapping of object-oriented entities to relational database table entries (OR Mapping) has become more and more popular in the development and design of various kinds of applications. The JPA (Java Persistence API) is a standard set up by Sun Microssystems to map Java data objects into relational database objects. JPA makes up for the deficiencies of JDBC, ORM, EJB2, and so on in Java object persistence, and is very easy to use. JPA uses the new features of the Java language such as annotations and generics, and requires the support of J2SE 1.5 (also known as Java 5) or later. The Apache OpenJPA is one of the many popular Java persistence implementations. The Apache OpenJPA is a Java persistence technology under the Apache Software fund that can be used as a standalone POJO (Plain old Java Object), or integrated into any Java EE-compatible container or other lightweight box Racks (such as Tomcat, Spring), and so on.

Standard JPA annotation and its application in OpenJPA

Standard JPA provides a number of annotation, and the use of these standard annotation in OpenJPA is as follows:

@entity

@entity used to declare a class as a persisted entity class. The annotation has only the only optional attribute, that is, name is used to specify the names of the entities.

@table

@table describes the information for a database table that corresponds to an entity class. @table have the following properties:

String Name: The name of the table.

String Schema: The schema that corresponds to the table, and if the name of the schema is not specified, JPA uses the default schema when the database is connected.

String Catalog: Table of Contents. If no directory is specified, JPA uses the default values when connecting to the database.

Uniquecontraint[] uniquecontraints: Unique constraint applied to a table. The uniquecontraint itself is a annotation that ensures that a column of a database table (a simple data type or a complex data type) is unique in each record.

@column

@column defines the properties for each column of a database table entry, including the following:

String Name: Specifies the name of the column, and the default value is the field name of the class.

String columndefinition: Database system-specific column type name. In OpenJPA, this property applies only to database systems where the database system can create tables directly from the metadata. During the creation of a table, if the property value is not empty, the database system defines the specified column with the type specified by the property.

int length: Specifies the length of the column.

int precision: The precision of small series.

int scale: Defines the maximum number of digits that can be accommodated in a column of a decimal type

Boolean nullable: Whether the column can accept Non-null records.

Boolean insertable: Defines whether the column can specify a build through an SQL INSERT statement, and the default value is true.

Boolean updatable: Defines whether the column can be generated through an SQL UPDATE statement, and the default value is true.

String table: Sometimes the column is not defined under the primary table, and the table property provides a way to map the column to the secondary table.

@ Inheritance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.