43 lines
1.1 KiB
Java
Executable File
43 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;
|
|
import jakarta.persistence.SequenceGenerator;
|
|
|
|
/**
|
|
* Insert-scenario twin of {@link WidgetIdentity}. Docs: docs/03-inserting-objects.md.
|
|
*
|
|
* <p>{@code allocationSize} matches {@code hibernate.jdbc.batch_size} in
|
|
* {@code application-insert-sequence.yml} on purpose: a mismatched allocation size is its own
|
|
* classic footgun (extra round trips to refill the sequence pool mid-batch) and not one this
|
|
* repo is trying to demonstrate here.
|
|
*/
|
|
@Entity
|
|
public class WidgetSequence {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "widget_seq")
|
|
@SequenceGenerator(name = "widget_seq", sequenceName = "widget_seq", allocationSize = 25)
|
|
private Long id;
|
|
|
|
private String name;
|
|
|
|
protected WidgetSequence() {
|
|
// JPA
|
|
}
|
|
|
|
public WidgetSequence(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
}
|