question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Create a micronaut Application with Entity using a composite ID with @EmbeddedId
  2. Create a corresponding JdbcRepository
  3. Add Data to the database table
  4. 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:open
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dstepanovcommented, Nov 8, 2021

I’m planning to improve expandable queries for the next release, I might be able to improve this as well

0reactions
ksawerykarwackicommented, Nov 5, 2021

Any plans to implement that? Currently the only way to achieve fast delete is to use native queries manually.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found