Столкнулся с такой ситуацией, что нужно записать большое количество строк в таблицу postgres, где ключем выступает поле типа string.
create table manual_securityдоступа к таблице у меня нет, изменить не могу. т.е. например добавить в нее поле типа int и
(
isin_code varchar(12) not null,
emitent_id numeric,
update_date_time timestamp not null,
constraint manual_security_pk primary key (isin_code)
);
create sequence manual_security_security_id_auto_gen increment 100;
я прочел в документации, что SEQUENCE is used for delegating the identifier generation to a database sequence.по документации в случае GenerationType.IDENTITY Spring ИГНОРИРУЕТ батчевую вставку, даже если она включена в настройках.
т.е. чтобы использовать батчевую вставку - нужно, чтобы в классе entity полем был ключ с типом integer и GenerationType.SEQUENCE
вот так
@Id
@SequenceGenerator(name = "manual_security_security_id_auto_gen", allocationSize = 100, sequenceName = "manual_security_security_id_auto_gen", initialValue = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "manual_security_security_id_auto_gen")
private Integer securityId;
вопрос к знатокам hibernate - можно ли как-то включить batch и добиться быстрого батчевого сохранения строк в таблице где ключем выступает string.сейчас класс и репозиторий выглядят так.
@Entityсохарнение saveall коллекции из 4к записей занимает так около 10 минут.
@Table(name = "manual_security")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@EqualsAndHashCode(of = "isinCode")
public class ManualSecurity {
@Id
@NotNull
@Column(name = "isin_code", nullable = false)
private String isinCode;
// остальные поля
}
public interface ManualSecurityRepository extends JpaRepository<ManualSecurity, String> {
}
настройки драйвера
jpa:Java задачи с собеседований
show-sql: false
open-in-view: false
database: postgresql
properties:
hibernate:
jdbc:
batch_size: 100