I use the following code
EntityManager em.createNativeQuery("insert into users (name,surname) values (\"Test\",\"Test\") returning id").executeUpdate();
executeUpdate method return me 1 if insertion was success, but how can i get id of new user using the query above(my db is Postgres);
Instead of executeUpdate
you can use getSingleResult()
to get the returned id
from Postgres.
Refer here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With