# Add Soft Delete to a Quarkus Panache Entity

Yes. An agent marks your Panache entities with Hibernate's @SoftDelete, fixes the seed data, adds restore routes and tests, and opens a PR that passes ./mvnw verify.

[Run this on Rush](https://cloud.getrush.ai/run/add-soft-delete/quarkus/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the entity mappings and the seed script before it touches a delete, because soft delete changes what a `DELETE` statement means and what a plain `INSERT` must now provide. In a service shaped like the `hibernate-orm-panache-quickstart` in quarkusio/quarkus-quickstarts, `pom.xml` imports `quarkus-bom 3.40.1.1`, depends on `quarkus-hibernate-orm-panache`, `quarkus-rest-jackson`, `quarkus-jdbc-postgresql`, `quarkus-junit` and `rest-assured`, targets Java 17 and builds with the Maven wrapper at 3.9.11. Two mappings of the same table shape live side by side: `entity/FruitEntity` extends `PanacheEntity` with a `@Column(length = 40, unique = true) name`, and `repository/Fruit` is a plain `@Entity` served through `FruitRepository implements PanacheRepository<Fruit>`. Both are `@Cacheable`.

`FruitEntityResource` at `entity/fruits` and `FruitRepositoryResource` at `repository/fruits` expose the same five operations: list sorted by name, get one, create (422 when an id is sent), update (422 without a name) and `DELETE {id}` answering 204, with a shared `ErrorMapper` that turns any exception into JSON. `src/main/resources/import.sql` inserts Cherry, Apple and Banana into both tables with explicit ids and restarts the sequences at 4, and `application.properties` loads that script on every start and logs SQL. Nothing in the tests or resources knows about a deleted row yet.

Quarkus 3.40 ships a Hibernate ORM that supports `org.hibernate.annotations.SoftDelete`, so the agent annotates both `FruitEntity` and `Fruit` with `@SoftDelete` rather than hand-writing a flag and a filter. With it, `entity.delete()` and `fruitRepository.delete(...)` issue an `UPDATE … SET deleted = true`, and every query Panache runs excludes those rows automatically. The generated column is `deleted boolean not null`, which breaks the existing `import.sql` inserts, so the agent adds `deleted` with `false` to each `INSERT`. It then adds `POST entity/fruits/{id}/restore` and the repository twin, implemented as a native `UPDATE fruitEntity SET deleted = false WHERE id = ?`, because the mapping hides deleted rows from HQL by design, and a `GET …/deleted` listing with a native select for the same reason.

`FruitsEndpointTest` already deletes id 1 and asserts Cherry is gone from the list, and `FruitsEndpointIT` runs the same class as a `@QuarkusIntegrationTest`. The agent keeps both green and adds assertions in the same class: after the delete, `GET …/deleted` names Cherry, `POST …/1/restore` returns 204 and the list contains Cherry again, and a repeat `DELETE` of a soft-deleted id answers 404, which the resources already return for an unknown id. It runs `./mvnw test`, which uses Dev Services to start Postgres in the sandbox, then `./mvnw verify` for the integration test, and pastes both summaries in the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add soft delete to the fruit entities in this Quarkus service and open a pull request. Read pom.xml, src/main/resources/application.properties, src/main/resources/import.sql, src/main/java/org/acme/hibernate/orm/panache/entity/FruitEntity.java, entity/FruitEntityResource.java, repository/Fruit.java, repository/FruitRepository.java, repository/FruitRepositoryResource.java and both test classes first. Annotate FruitEntity and Fruit with org.hibernate.annotations.SoftDelete. Update every INSERT in import.sql to set the deleted column to false. Add POST {id}/restore to both resources using a native update that clears the flag, returning 204, and GET deleted on both using a native select of soft-deleted rows. Extend FruitsEndpointTest so that after deleting id 1 the deleted listing names Cherry, restore brings it back to the list, and a second delete of a soft-deleted id answers 404. Run ./mvnw test and ./mvnw verify and paste both summaries in the pull request. Do not change the response shapes of the existing five routes.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds one annotation and one import to `FruitEntity.java` and `Fruit.java`, a `deleted` value to the six `INSERT` lines in `import.sql`, two new methods in each resource class, and new assertions in `FruitsEndpointTest.java`. The description quotes the `UPDATE fruitEntity set deleted=true where id=?` line from the SQL log that `application.properties` turns on, as evidence that the delete no longer removes the row, and the `./mvnw verify` summary.

A pull request build that runs `./mvnw clean install` with containers, as the quickstarts' own workflow does, executes both the `@QuarkusTest` and the `@QuarkusIntegrationTest`, so a mapping error or a failing seed script shows up there before review.

A reviewer checks that the `deleted` column default is right for their production `schema-management.strategy`, that the restore route is native SQL because HQL cannot see the row, that `@Cacheable` entities do not serve a deleted fruit from the second-level cache after the update, and that the unique constraint on `name` is what they want while a soft-deleted Cherry still occupies the name. Then they run the schema change on staging.

## Run it on every entity that must keep history

A team moving several Quarkus services from hard deletes to recoverable ones sends one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`. Each run reads its own entities, so a service on an older Hibernate without `@SoftDelete` gets a `deleted` column with an explicit `@SQLRestriction` instead, and each opens its own pull request.

Send a `request_id` with each body so a retried call returns the run already started rather than a second one. With a `webhook_url` on the API key, Rush POSTs `run.completed` when each turn ends, with the `session_url` to read the pull request from.

## Why run it on Rush?

Soft delete is a change you only trust after seeing the SQL. In a Rush sandbox the agent runs `./mvnw test` with Dev Services starting a real Postgres, and because this project logs SQL, the `UPDATE … SET deleted = true` that replaced the `DELETE` sits in the run's record next to the command that produced it. A reviewer reads what Hibernate actually emitted rather than what the annotation's documentation promises.

The seed script is where this change usually bites: a new `not null` column makes every existing `INSERT` fail on first start. The agent hits that in the sandbox, fixes `import.sql`, and reruns until the tests pass, so the pull request arrives already past the failure a laptop run would have hit halfway through. The same request body works unchanged across every Quarkus service a team runs, several at once.

## Frequently asked questions

### Why @SoftDelete instead of a boolean field and a filter?

Because the Hibernate ORM that Quarkus 3.40 bundles supports it natively: deletes become updates and every HQL and Panache query excludes flagged rows without a `@SQLRestriction` on each entity or a `where` clause in each finder. One annotation on each of the two mappings covers every existing route in both resources.

### Why does import.sql change?

The annotation adds a `deleted boolean not null` column to the generated schema, and the existing `INSERT INTO fruitEntity(id, name)` lines do not set it, so the seed fails on first start. Adding `deleted` with `false` to each line keeps Cherry, Apple and Banana loading as before.

### How do I read or restore a deleted row?

Not through HQL: the mapping hides soft-deleted rows from every entity query on purpose. The pull request adds `GET …/deleted` and `POST …/{id}/restore` built on native SQL, which is the one place in the service that sees the flag directly.

### What about the unique name constraint?

A soft-deleted Cherry still holds the name, so creating a new Cherry answers 500 through the `ErrorMapper` until it is restored or force-deleted. The pull request notes this and leaves the choice, a partial unique index on live rows or a restore-first rule, to the reviewer.

### Does it run in CI?

The quickstarts build with `./mvnw clean install` and a flag to start containers, which runs both `FruitsEndpointTest` and `FruitsEndpointIT`. The agent adds no new workflow; the existing build covers the change.

## More Quarkus jobs

- [Add Structured Logging to a Quarkus App](https://getrush.ai/run/add-structured-logging/quarkus/)
- [Review Pull Requests on a Quarkus Service](https://getrush.ai/run/review-pull-requests/quarkus/)
- [Upgrade a Quarkus App to Java 25](https://getrush.ai/run/upgrade-java-version/quarkus/)

## The same job on other stacks

- [Add Soft Delete to Sequelize Models in an Express App](https://getrush.ai/run/add-soft-delete/sequelize/)
- [Add Soft Delete to SQLAlchemy Models](https://getrush.ai/run/add-soft-delete/sqlalchemy/)
- [Add Soft Delete to a sqlc Project](https://getrush.ai/run/add-soft-delete/sqlc/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
