0

This is my first time asking here, so sorry if I don’t fully explain myself. I am using Java with Spring boot and Hibernate. I am mostly using auto increment primary keys for almost all my Entities since I read it is a good practice and it is optimal for indexing. I have an entity that its primary key is autoincrement. That is the only value which is unique for said entity, now I want to get the object by that id but I’m not sure how I can provide said id from the client side since it is generated automatically, and since that is the only unique value for which I can differentiate each column, how can I send the ID from the client side in order to get said Object, or verify if another object matches that one, without having that auto generated value?

  • If there are no other unique property, the client has to search the correct entity. You could write different ```findBy``` methods (server-side) to find the correct entity. If you found it, you've got the ID to go on. – Thilo Schwarz May 07 '22 at 09:42
  • @williamarias4, your DB design is likely flawed if the only unique column is the autoincrement column. Since you haven't provided any information regarding the content of the table in question, it's hard to give a more specific answer. – dsp_user May 07 '22 at 10:18
  • Also duplicate of https://stackoverflow.com/q/2853066/642706 and https://stackoverflow.com/questions/1915166/how-to-get-the-insert-id-in-jdbc – Basil Bourque May 07 '22 at 19:27

0 Answers0