Retrieving the generated identifier for an embedded JPA request

For performance reasons, I need to use some native queries to insert new objects into the database. I have a very complicated JPA persistence level that governs my normal reading and writing of entities, and I would like to use this persistence level to run my own queries.

I know that to achieve my goal I need the methods EntityManager # createNativeQuery (String) and Query # executeUpdate.

My current problem is that I would also like to get the generated id of the newly inserted row. I know this is possible using JDBC or SpringPersistence, but is there a way to get these identifiers from my own JPA request?

+2
source share
1 answer

Most often this is database specific, and if you can do it using JDBC, you can do it also using your own JPA request. To get the inserted identifier, you need to perform an additional (database-specific) request.

+2
source

Source: https://habr.com/ru/post/1269477/


All Articles