我有一张桌子" bon_sav"其id具有递增序列(" bon_sav_id_seq")
还创建了另一个名为" hibernate_sequence"
的序列我的问题是我的桌子" bon_sav"使用序列" hibernate_sequence"而不是" bon_sav_id_seq"。我有其他表使用这个序列" hibernate_sequence"所以我可能很快就会遇到问题。
有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);
在Java中,在我的课堂上,我有:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
你知道为什么这是正确使用的序列吗?
答案 0 :(得分:1)
请看这个解决方案:Configure JPA to let PostgreSQL generate the primary key value
尝试提及序列名称如下(参见链接中的完整解决方案):
@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;
我不知道继续创建序列的最佳方法是什么,但您可以让Postgresql根据链接
中的建议使用 SERIAL 类型生成它