generate DB record id in the DB and not in java

hey guys. i have pojo that is being inserted into my DB. i dont want to have id field in my pojo and let my DB generate record id. can i do it somehow? thanks
7 Replies
JavaBot
JavaBot5mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Peter Rader
Peter Rader5mo ago
Is your Pojo an Entity? What is your database vendor? Postgres, Oracle, Mysql?
Kyo-chan
Kyo-chan5mo ago
My questions would be what counts as the DB and what counts as Java. As far as the DB is concerned, objects don't exist. you call INSERT statements to it. That's it. Admittedly some while allow to create columns where an id is automatically created when inserting a row in their table, but that doesn't sound much like what's asked.
Peter Rader
Peter Rader5mo ago
@Kyo-chan Depends, Postgres usually use a sequence to notify the next free number. Oracle 12c can use the new built-in column type identity (https://oracle-base.com/articles/12c/identity-columns-in-oracle-12cr1) what is the most clean solution. The primary-key annotation must differ depending on the database implementation!
Kyo-chan
Kyo-chan5mo ago
......... That doesn't address what I was saying
Peter Rader
Peter Rader5mo ago
Yes, sorry, you are right.
JavaBot
JavaBot5mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server