0

I have a table "bon_sav" whose id has a sequence for incrementation ("bon_sav_id_seq")

There is another sequence that has been created called "hibernate_sequence"

My problem is that my table "bon_sav" uses the sequence "hibernate_sequence" instead of "bon_sav_id_seq". I have other tables that use this sequence "hibernate_sequence" so I may have a problem quickly.

There is the script for create table bon_sav

CREATE TABLE bon_sav (
id bigint NOT NULL,
uuid character varying(40) NOT NULL,
logiciel_id character varying(40) NOT NULL,
code_magasin character varying(10),
numero_fournisseur character varying(40),
date_depot date NOT NULL,
date_retrait date,
code_client character varying(10) NOT NULL,
nom_client character varying(30),
prenom_client character varying(30),
email_client character varying(50),
telephone_client character varying(20),
url_photo character varying(255),
date_creation timestamp without time zone NOT NULL,
date_modification timestamp without time zone,
date_suppression timestamp without time zone,
est_supprimer boolean,
entite_id bigint,
nature_id bigint,
type_id bigint,
lieu_id bigint,
etat_id bigint,
destinataire_id bigint,
createur_id bigint,
modificateur_id bigint,
supprimeur_id bigint,
nom_produit character varying(100) DEFAULT ' '::character varying NOT NULL,
detail_produit text
);


ALTER TABLE bon_sav OWNER TO yvidya;

--
-- TOC entry 222 (class 1259 OID 16594)
-- Name: bon_sav_id_seq; Type: SEQUENCE; Schema: public; Owner: yvidya
--

CREATE SEQUENCE bon_sav_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE bon_sav_id_seq OWNER TO yvidya;

--
-- TOC entry 2279 (class 0 OID 0)
-- Dependencies: 222
-- Name: bon_sav_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: yvidya
--

ALTER SEQUENCE bon_sav_id_seq OWNED BY bon_sav.id;


--
-- TOC entry 2143 (class 2604 OID 16599)
-- Name: bon_sav id; Type: DEFAULT; Schema: public; Owner: yvidya
--

ALTER TABLE ONLY bon_sav ALTER COLUMN id SET DEFAULT nextval('bon_sav_id_seq'::regclass);

And in Java, in my class, I have :

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;

Would you know why this is the right sequence that is used?

MWiesner
  • 8,868
  • 11
  • 36
  • 70
user1450740
  • 731
  • 10
  • 26

1 Answers1

1

Look at this solution: Configure JPA to let PostgreSQL generate the primary key value

Try to mention sequence name as follow (see the complete solution in the link):

@Id
@SequenceGenerator(name="webuser_idwebuser_seq",
                   sequenceName="webuser_idwebuser_seq",
                   allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
                generator="webuser_idwebuser_seq")
@Column(name = "idwebuser", updatable=false)
private Integer id;

I don't know what is the best way to proceed creating sequences but you might let Postgresql generate it for your using the SERIAL type as recommended in the link

jMounir
  • 495
  • 2
  • 11