When you create an entity in JPA, you declare the primary key of the entity and its primary key generation policy. We have an entity class called email, whose primary key is declared as follows:
@Id
@Column (name = "email_id")
@GeneratedValue
MySQL primary key auto-generated table design MySQL has many primary key generation strategies, and one of the most common is auto-generated. In general, the primary key type is bigint UNSIGNED, and the keyword that automatically generates the
How to specify an ID policy
In JPA, we specify ID primary key and ID policy through @id and @generatedvalue, such as:
@Id
@GeneratedValue (strategy = Generationtype.auto)
@Column (name = "Id")
private String ID;
This also specifies the ID and the
Hibernate generator primary key generation policy, hibernategenerator
"Assigned"A primary key is generated by an external program and specified before save."Hilo"The primary key generation mechanism implemented by the hi/lo algorithm requires
When using MyBatis, it is necessary to write a large number of mapping mapping files, manual writing is heavy and error prone. Fortunately, Mybatis-generator can be used to help us automatically generate these files, greatly improving the efficiency
@ Generatedvalue: The primary key generation policy, which is specified through the Strategy attribute.
The primary key generation policy is specified by generationtype. Generationtype is an enumeration that defines the type of primary key
ID of an Object relational database mappingThe mapped class must define the corresponding database table primary key field. Most classes have a JavaBeans-style attribute that includes unique identities for each instance.The element defines the
Saving the value of the current primary key to a table in a database, and the primary key's value is obtained each time from the specified table, the way to generate the primary key is also very common. This method of generating a primary key can be
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.