42 lines
1.1 KiB
Java
Executable File
42 lines
1.1 KiB
Java
Executable File
package com.ankurm.hibernatedemo.model;
|
|
|
|
import jakarta.persistence.Entity;
|
|
import jakarta.persistence.GeneratedValue;
|
|
import jakarta.persistence.GenerationType;
|
|
import jakarta.persistence.Id;
|
|
|
|
/**
|
|
* Insert-scenario twin of {@link WidgetSequence}, identical except for the id generation
|
|
* strategy. Docs: docs/03-inserting-objects.md.
|
|
*
|
|
* <p>{@code IDENTITY} requires the database to hand back the generated key on every single
|
|
* insert, which is exactly why it defeats JDBC batching — see the captured output in
|
|
* docs/output/insert-identity.txt versus docs/output/insert-sequence.txt for the same
|
|
* {@code hibernate.jdbc.batch_size} setting producing very different behaviour.
|
|
*/
|
|
@Entity
|
|
public class WidgetIdentity {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
private String name;
|
|
|
|
protected WidgetIdentity() {
|
|
// JPA
|
|
}
|
|
|
|
public WidgetIdentity(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
}
|