Delete all method for entities with @EmbeddedId does not use IN for better performance
See original GitHub issue- Steps to reproduce provided
- Stacktrace (if present) provided not present
- Example that reproduces the problem uploaded to Github
- Full description of the issue provided (see below)
Steps to Reproduce
- Create a micronaut Application with Entity using a composite ID with @EmbeddedId
- Create a corresponding JdbcRepository
- Add Data to the database table
- Invoke
deleteAll(Collection<Entity>)
on the Repository to delete some selected Entities
Expected Behaviour
Micronaut data generates and executes one single SQL query using the IN clause in case the selected Dialect supports IN clauses with multiple columns (most do).
Actual Behaviour
Micronaut data interates the provided entities and executes one DELETE statement per entity, this rapidly cuts down performance for large collections of entities.
Environment Information
- Operating System: Windows 10
- Micronaut Version: 1.3.0.RC1
- JDK Version: 1.8
Example Application
The master
branch demonstrates the issue (execute the application -> logging will show two executed delete statements).
11:19:04.351 [main] DEBUG io.micronaut.data.query - Executing Query: SELECT book_.`hash`,book_.`name`,book_.`author` FROM `Book` book_
11:19:04.367 [main] DEBUG de.ksmwsk.deleteall.BookDeleter - Found 4 books before deletion
11:19:05.389 [main] DEBUG io.micronaut.data.query - Executing Query: DELETE FROM `Book` WHERE (hash = ? AND name = ?) <------------------
11:19:05.392 [main] DEBUG io.micronaut.data.query - Executing Query: DELETE FROM `Book` WHERE (hash = ? AND name = ?) <------------------
11:19:05.392 [main] DEBUG io.micronaut.data.query - Executing Query: SELECT book_.`hash`,book_.`name`,book_.`author` FROM `Book` book_
11:19:05.393 [main] DEBUG de.ksmwsk.deleteall.BookDeleter - Found 2 books after deletion
The simple-id
branch demonstrates the behaviour with simple (non-embedded) ideas which i would also expect from the version with the EmbeddedId
11:05:28.897 [main] DEBUG io.micronaut.data.query - Executing Query: SELECT book_.`hash`,book_.`name`,book_.`author` FROM `Book` book_
11:05:28.912 [main] DEBUG de.ksmwsk.deleteall.BookDeleter - Found 4 books before deletion
11:05:29.933 [main] DEBUG io.micronaut.data.query - Executing Query: DELETE FROM `Book` WHERE (hash IN(?,?)) <----------------------------
11:05:29.938 [main] DEBUG io.micronaut.data.query - Executing Query: SELECT book_.`hash`,book_.`name`,book_.`author` FROM `Book` book_
11:05:29.939 [main] DEBUG de.ksmwsk.deleteall.BookDeleter - Found 2 books after deletion
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
JPA Query to deleteById for a Composite Key declared using ...
Ultimately, I want to do this to batch my DELETE requests to increase the performance. Pitfalls I'm trying to avoid. I know there...
Read more >Composite key handling, using @EmbeddedId annotation in ...
In this method Id class introduction is done by @EmbeddedId annotation. As I explained in previous blog mapping details are added in this...
Read more >Spring JPA @Embedded and @EmbeddedId - Baeldung
In this tutorial, we're going to cover the use of the @EmbeddedId annotation and “findBy” method for querying a composite key based JPA...
Read more >Micronaut Data - GitHub Pages
To save an instance use the save method of the CrudRepository interface: ... Since Micronaut Data is a build time tool, it will...
Read more >OpenJPA User's Guide
OpenJPA is Apache's implementation of Sun's Java Persistence API (JPA) ... For all of these reasons and more, object databases have not caught...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m planning to improve expandable queries for the next release, I might be able to improve this as well
Any plans to implement that? Currently the only way to achieve fast delete is to use native queries manually.