You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is likely not an issue but more a lack of understanding on my behalf, but i just cant seem to find any answers to this. I am keeping track of entity IDs using GenerationType.SEQUENCE for which i create my sequencers manually. Consider the following:
Mapping of my CmsLanguage id:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cms_language_seq")
@SequenceGenerator(name = "cms_language_seq", sequenceName = "cms_language_seq")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
Creation of my CmsLanguage table (DBeaver):
CREATE SEQUENCE cms_language_seq;
CREATE TABLE cms_language (
id BIGINT PRIMARY KEY default nextval('cms_language_seq'),
lang_enum VARCHAR(2) NOT NULL UNIQUE,
cms_configuration_id BIGINT NOT NULL,
CONSTRAINT fk_cms_configuration FOREIGN KEY (cms_configuration_id) REFERENCES cms_configuration(id) ON DELETE CASCADE
);
The problem:
Upon running currval('cms_language_seq') and currval('cms_languagelang_seq') in DBeaver, i get 3 and 9 respectively, as expected.
When i then launch my api, and start making inserts via my repositories, everything seems to be working fine. the next sequential ids are being generated. However, when i then request the current sequence values in DBeaver, they have not updated. They remain 3 and 9. It seems as though Hibernate starts off with the initially provided sequence values, makes a copy of those sequences internally, and uses this copy to continue generating sequential ids. A virtual sequence if you will.
Secondly, when i then shut down my application and restart, the "internal" current sequence values do not remain updated as they seemed to be from the last inserts via my repository, but it seems like they are 3 and 9 again. Because entities have now been persisted in my database with higher IDs, i get duplicate primary key value violation errors.
If someone could enlighten me about what i am missing here, it would be highly appreciated.
Thanks in advance,
Bert
The text was updated successfully, but these errors were encountered:
This is likely not an issue but more a lack of understanding on my behalf, but i just cant seem to find any answers to this. I am keeping track of entity IDs using GenerationType.SEQUENCE for which i create my sequencers manually. Consider the following:
Mapping of my CmsLanguage id:
Creation of my CmsLanguage table (DBeaver):
Some initial inserts (DBeaver):
The problem:
Upon running currval('cms_language_seq') and currval('cms_languagelang_seq') in DBeaver, i get 3 and 9 respectively, as expected.
When i then launch my api, and start making inserts via my repositories, everything seems to be working fine. the next sequential ids are being generated. However, when i then request the current sequence values in DBeaver, they have not updated. They remain 3 and 9. It seems as though Hibernate starts off with the initially provided sequence values, makes a copy of those sequences internally, and uses this copy to continue generating sequential ids. A virtual sequence if you will.
Secondly, when i then shut down my application and restart, the "internal" current sequence values do not remain updated as they seemed to be from the last inserts via my repository, but it seems like they are 3 and 9 again. Because entities have now been persisted in my database with higher IDs, i get duplicate primary key value violation errors.
If someone could enlighten me about what i am missing here, it would be highly appreciated.
Thanks in advance,
Bert
The text was updated successfully, but these errors were encountered: