gpt4 book ai didi

java - 为什么 postgresql 不使用正确的顺序?

转载 作者:行者123 更新时间:2023-12-02 11:40:20 25 4
gpt4 key购买 nike

我有一个表“bon_sav”,其 id 有一个递增序列(“bon_sav_id_seq”)

还创建了另一个序列,称为“hibernate_sequence”

我的问题是我的表“bon_sav”使用序列“hibernate_sequence”而不是“bon_sav_id_seq”。我有其他表使用这个序列“hibernate_sequence”,所以我可能很快就会遇到问题。

有创建表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;

您知道为什么这是正确的顺序吗?

最佳答案

看看这个解决方案: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 类型为您生成序列

关于java - 为什么 postgresql 不使用正确的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48624585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com