Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA native query insert returning id

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);

like image 990
Almas Abdrazak Avatar asked Oct 15 '25 14:10

Almas Abdrazak


1 Answers

Instead of executeUpdate you can use getSingleResult() to get the returned id from Postgres.

Refer here

like image 60
Ram Avatar answered Oct 17 '25 04:10

Ram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!