Skip to content

Commit

Permalink
Passe l'allocationsize des sequences GenerationType.SEQUENCE à 1
Browse files Browse the repository at this point in the history
Par défaut Hibernate a un allocationSize à 50, et alloue des paquets de 50
pour chaque valeur réelle de la séquence soit [curVal50, curVal50 + 50-1],
ce qui empêche l'insertion par un autre biais (SQL, PDI).
Remettre un allocationSize à 1 permet une utilisation "normale" de la
séquence

Issue : #204332

Change-Id: I68767cb040eb2bf7586d34c040f20fce23af1937
  • Loading branch information
Renaud-Kieffer committed Feb 2, 2024
1 parent 232c71f commit 3fee4b1
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public class HydrantIndispoTemporaire {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "indispo_temp_seq")
@SequenceGenerator(name = "indispo_temp_seq", sequenceName = "hydrant_indispo_temporaire_id_seq")
@SequenceGenerator(
allocationSize = 1,
name = "indispo_temp_seq",
sequenceName = "hydrant_indispo_temporaire_id_seq")
@Column(name = "id")
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class TypeHydrantIndispoStatut {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_hydrant_indispo_statut_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_hydrant_indispo_statut_seq",
sequenceName = "type_hydrant_indispo_statut_id_seq")
@Column(name = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public class TypeOldebAcces {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_oldeb_acces_seq")
@SequenceGenerator(name = "type_oldeb_acces_seq", sequenceName = "type_oldeb_acces_id_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_acces_seq",
sequenceName = "type_oldeb_acces_id_seq")
@Column(name = "id")
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public class TypeOldebAction {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_oldeb_action_seq")
@SequenceGenerator(name = "type_oldeb_action_seq", sequenceName = "type_oldeb_action_id_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_action_seq",
sequenceName = "type_oldeb_action_id_seq")
@Column(name = "id")
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public class TypeOldebAnomalie {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_oldeb_anomalie_seq")
@SequenceGenerator(name = "type_oldeb_anomalie_seq", sequenceName = "type_oldeb_anomalie_id_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_anomalie_seq",
sequenceName = "type_oldeb_anomalie_id_seq")
@Column(name = "id")
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public class TypeOldebAvis implements ITypeReferenceNomActif {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_oldeb_avis_seq")
@SequenceGenerator(name = "type_oldeb_avis_seq", sequenceName = "type_oldeb_avis_id_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_avis_seq",
sequenceName = "type_oldeb_avis_id_seq")
@Column(name = "id")
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TypeOldebCaracteristique {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_oldeb_caracteristique_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_caracteristique_seq",
sequenceName = "type_oldeb_caracteristique_id_seq")
@Column(name = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TypeOldebCategorieAnomalie {
strategy = GenerationType.SEQUENCE,
generator = "type_oldeb_categorie_anomalie_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_categorie_anomalie_seq",
sequenceName = "type_oldeb_categorie_anomalie_id_seq")
@Column(name = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TypeOldebCategorieCaracteristique {
strategy = GenerationType.SEQUENCE,
generator = "type_oldeb_categorie_caracteristique_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_categorie_caracteristique_seq",
sequenceName = "type_oldeb_categorie_caracteristique_id_seq")
@Column(name = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class TypeOldebDebroussaillement {
strategy = GenerationType.SEQUENCE,
generator = "type_oldeb_debroussaillement_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_debroussaillement_seq",
sequenceName = "type_oldeb_debroussaillement_id_seq")
@Column(name = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class TypeOldebResidence {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_oldeb_residence_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_residence_seq",
sequenceName = "type_oldeb_residence_id_seq")
@Column(name = "id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class TypeOldebZoneUrbanisme {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "type_oldeb_zone_urbanisme_seq")
@SequenceGenerator(
allocationSize = 1,
name = "type_oldeb_zone_urbanisme_seq",
sequenceName = "type_oldeb_zone_urbanisme_id_seq")
@Column(name = "id")
Expand Down
45 changes: 45 additions & 0 deletions server/sdis-remocra/home/postgres/remocra_db/patches/196/196.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
begin;
set statement_timeout = 0;
set client_encoding = 'UTF8';
set standard_conforming_strings = off;
set check_function_bodies = false;
set client_min_messages = warning;
set escape_string_warning = off;
set search_path = remocra, pdi, public, pg_catalog;
--------------------------------------------------
-- Versionnement du patch et vérification
--
create or replace function versionnement_dffd4df4df() returns void language plpgsql AS $body$
declare
numero_patch int;
description_patch varchar;
begin
-- Métadonnées du patch
numero_patch := 196;
description_patch := 'Remet toutes les séquences gérées par hibernate à jour';

-- Vérification
if (select numero_patch-1 != (select max(numero) from remocra.suivi_patches)) then
raise exception 'Le numéro de patch requis n''est pas le bon. Dernier appliqué : %, en cours : %', (select max(numero) from remocra.suivi_patches), numero_patch; end if;
-- Suivi
insert into remocra.suivi_patches(numero, description) values(numero_patch, description_patch);
end $body$;
select versionnement_dffd4df4df();
drop function versionnement_dffd4df4df();
--------------------------------------------------
-- Contenu réel du patch début
SELECT setval('hydrant_indispo_temporaire_id_seq', (SELECT MAX(id) FROM remocra.hydrant_indispo_temporaire)+1);
SELECT setval('type_hydrant_indispo_statut_id_seq', (SELECT MAX(id) FROM remocra.type_hydrant_indispo_statut)+1);
SELECT setval('type_oldeb_acces_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_acces)+1);
SELECT setval('type_oldeb_action_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_action)+1);
SELECT setval('type_oldeb_anomalie_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_anomalie)+1);
SELECT setval('type_oldeb_avis_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_avis)+1);
SELECT setval('type_oldeb_caracteristique_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_caracteristique)+1);
SELECT setval('type_oldeb_categorie_anomalie_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_categorie_anomalie)+1);
SELECT setval('type_oldeb_categorie_caracteristique_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_categorie_caracteristique)+1);
SELECT setval('type_oldeb_debroussaillement_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_debroussaillement)+1);
SELECT setval('type_oldeb_residence_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_residence)+1);
SELECT setval('type_oldeb_zone_urbanisme_id_seq', (SELECT MAX(id) FROM remocra.type_oldeb_zone_urbanisme)+1);
-- Contenu réel du patch fin
--------------------------------------------------
COMMIT;

0 comments on commit 3fee4b1

Please sign in to comment.