I am trying to perform Batch Insert with spring data jpa and Hibernate but the problem is Hibernate only supports batch inserts when the generated value strategy is SEQUENCE but somehow sqlite does not support this strategy so I resort to Identity which works fine but does not support batching with hibernate. Is there any solution or workaround for this.
Entity
@Entity
@Table(name = "party")
public class PartyEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "party_id", nullable = false)
private Long id;
@Column(name = "party_name", unique = true)
@NonNull
private String name;
@Column(name = "party_phone_number", unique = true)
private Long number;
}
SQLite do have this table called 'sqlite_sequence' which I try to use with @SequenceGenerator but hibernate tries to create this table which we cannot as this is a reserved table. And same goes for @TableGenerator.
Annotation for sequence used
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "party_seq")
@SequenceGenerator(name = "party_seq", sequenceName = "sqlite_sequence", allocationSize = 1)
Annotation for table used
@GeneratedValue(strategy = GenerationType.TABLE, generator = "sqlite_generator")
@TableGenerator(name = "sqlite_generator", table = "sqlite_sequence", pkColumnName = "name",
valueColumnName = "seq", pkColumnValue = "party", initialValue = 1, allocationSize = 1)
DDL script for the table
CREATE TABLE party (
party_id INTEGER PRIMARY KEY ASC AUTOINCREMENT,
party_name VARCHAR (256) UNIQUE
NOT NULL,
party_phone_number INTEGER (10) UNIQUE
);