Generator-jhipster: PostgreSQL : id's columns are generated with type "BIGINT NOT NULL" type and not "BIGSERIAL"

Created on 27 Nov 2017  路  4Comments  路  Source: jhipster/generator-jhipster

Overview of the issue

When using PostgreSQL, ID's column are generated with a "bigint not null" type instead of 'Bigserial' wich seem to be the correct way for an autoincrement primary key column.
This is an issue when you have to use scripts to insert a batch of values , also id's value start with weird values like '90201"

infos :

"generator-jhipster": {
"jhipsterVersion": "4.10.2",
"serverPort": "8080",
"authenticationType": "session",
"hibernateCache": "no",
"clusteredHttpSession": false,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "postgresql",
"prodDatabaseType": "postgresql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSocialSignIn": false,
"enableSwaggerCodegen": false,
"clientFramework": "angular1",
"useSass": false,
"clientPackageManager": "yarn",
"applicationType": "monolith",
"testFrameworks": [],
"jhiPrefix": "jhi",
"enableTranslation": false

All 4 comments

  • BigSerial is basically the same as what we do, it uses underneath a BigInt and a sequence
  • However, the way we use sequences should be more performant - and that's also your second question, about the "strange" numbers we generate. Have a look at the Hibernate HiLo algorithm - in fact this is all done by Hibernate, not us :-)
    See https://vladmihalcea.com/tag/hilo-algorithm/ for example
  • If you want to use this in a batch -> if you don't use Hibernate, you need to do the same algorithm to generate the IDs (not that difficult in fact), and be careful about the 2nd level cache (you need to reset it)

-> now maybe using a BigSerial would clean up a bit our code (the Liquibase part, for instance). And the performance could also be tested.

I'm closing this as:

  • I'm not sure there's any value (the doc is here) as those are merely convenience values
  • Changing this would impact everyone, we can't do this without a major release

Ok, thanks for the answers and the links.
I'm used to JHipster with Mysql and this id's behavior with postgres unsettled me a bit.
Maybe keep the generator like it is now by default, and set a property or a config somewhere to let user choose BigSerial over BigInt ?

@LousyJohnny it will not be worth the effort to have this as an option as it adds maintenance burden for us

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaidohallik picture kaidohallik  路  3Comments

ahmedeldeeb25 picture ahmedeldeeb25  路  3Comments

RizziCR picture RizziCR  路  3Comments

lsadehaan picture lsadehaan  路  3Comments

trajakovic picture trajakovic  路  4Comments