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 an issue. Every time after saving, I get a return value, where the id is generated only after saving to the database. So when I try to retrieve it, I find that it is 0, the id of the returned object is 0, indicating that the save() method does not return the object after saving.

After some research, I found that I need to add @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.