I currently a spring boot project with postgres and hibernate and had the following functions:
private fun savePost(post: Post): Post = entityManager.merge(post)
private fun savePosts(posts: List<Post>) =
posts.forEach { save(post) }
I wanted to avoid a sequential insert so now I have a raw query:
private fun savePosts(posts: List<Post>) {
val queryText: String = createTextQueryFromList(posts)
val query = entityManager.createNativeQuery(queryText)
query.executeUpdate()
}
This does work but it is not very clean.
What is the correct way for a bulk insert using criteria builder?