How does SpringDataJpa increase the table id of oracle by itself?
anyone who has used oracle knows that the self-increasing id, of oracle is usually implemented by sequence.
I only marked @ Id, on the entity and did not mark it to other additional comments. I thought there would be an error in save, but it actually helped me add my own id.
where on earth does spring-data-jpa maintain a self-incrementing record?
is there any official document parsing? Ask the great god for advice.
@ GeneratedValue
it is usually convenient to allow persistence implementations to automatically assign unique values to identity fields. JPA contains GeneratedValue annotations for this purpose. It has the following properties:
GenerationType policy: enumerates values that specify how field values are automatically generated. The GenerationType enumeration has the following values:
GeneratorType.AUTO: default value. Assigning the generated value to the field is up to the JPA vendor to decide the implementation (such as hibernate).
the GenerationType.IDENTITY: database will assign an identity value, such as MySQL's auto_increment, at insert time.
GenerationType.SEQUENCE: uses database sequences to generate field values, such as oracle.
GenerationType.TABLE: uses sequence tables to generate field values. As in the following example
@Entity
@Table(name = "JPAGEN_PERSON")
public class Person implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE,
generator = "personGen")
@TableGenerator(name = "personGen",
table = "JPAGEN_GENERATORS",
pkColumnName = "NAME",
pkColumnValue = "JPAGEN_PERSON_GEN",
valueColumnName = "VALUE")
private long id;
// other fields and methods are omitted
}
as to which method you say is related to the implementation of jpa, you can take a look at this link
https://docs.spring.io/spring.
but since the underlying implementation is still hibernate, you can refer to the implementation of hibernate
ide/html_single/Hibernate_User_Guide.html-sharpannotations-hibernate-generatortype" rel=" nofollow noreferrer "> http://docs.jboss.org/hiberna.