banner
RustyNail

RustyNail

coder. 【blog】https://rustynail.me 【nostr】wss://ts.relays.world/ wss://relays.world/nostr

save method of `JpaRepository` in spring data jpa

When using spring boot jpa, I encountered a problem. After each save, I get a return value, and the id in it is generated only after saving to the database.

When I tried to retrieve it, I found that it was 0, and the id of the returned object was 0, indicating that the save() method does not return the object after storage.

After searching, I found that I need to add the @GeneratedValue(strategy = GenerationType.IDENTITY) annotation to the id field of the Entity to return the latest id.

picture

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.