# Entity transient because soft-deleted?

**URL:** <https://discourse.hibernate.org/t/entity-transient-because-soft-deleted/11691>\
**Category:** Hibernate ORM\
**Created:** [July 31, 2025, 7:45am UTC](https://discourse.hibernate.org/t/entity-transient-because-soft-deleted/11691 "2025-07-31T07:45:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkomko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mkomko/32/2207_2.png) [@mkomko](https://discourse.hibernate.org/u/mkomko)\
**Post date:** [July 31, 2025, 7:45am UTC](https://discourse.hibernate.org/t/entity-transient-because-soft-deleted/11691/1 "2025-07-31T07:45:47Z")

</div>

Hey guys!

We have the following case (Hibernate 6.6.11.Final, WildFly 35, JPA):

```java
@Entity
@SQLDelete("UPDATE A SET DELETED = 1 WHERE ID=? AND ROW_VERSION=?", verify = Expectation.RowCount.class)
public class A {
    @Id
    private Long id;

    @ManyToOne
    @JoinColumn("B1_ID")
    private B b1;

    @ManyToOne
    @JoinColumn("B2_ID")
    private B b2;

    @Column("DELETED")
    private boolean deleted;

    @Version
    @Column(name = "ROW_VERSION")
    private int rowVersion;
}

@Entity
public class B {
    @Id
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "A_ID", referencedColumnName = "ID")
    private A a;

    @Column(name = "DELETE_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date deleteDate;

    @Version
    @Column(name = "ROW_VERSION")
    private int rowVersion;
}

```

What happens now is the following:

1. We _merge_ entity _A_. This also attaches entities _b1_ and _b2_ to the persistence context.
2. We _remove_ entity _B_.
3. When the transaction is flushed, we get a _TransientObjectException_ for `B#a`, because `CascadingActions#isChildTransient` returns _true_ because of `entry.getStatus().isDeletedOrGone()`.

In our thinking, it’s valid that _B_ still references the deleted _A_ because it was not really deleted. The deleted _A_ can also be found later, because it still exists in the DB. So should `CascadingActions#isChildTransient` consider that the entity was only soft-deleted and not say that it is transient?

What do you guys think? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [August 1, 2025, 9:00am UTC](https://discourse.hibernate.org/t/entity-transient-because-soft-deleted/11691/2 "2025-08-01T09:00:25Z")

</div>

Hi, this is an interesting edge case that probably also affects the built-in soft-delete of Hibernate ORM 7+ and is hard to give a good answer here. I guess there will be lots of opinions.

I would suggest you start a discussion on our [chat platform Zulip](https://hibernate.zulipchat.com/#narrow/stream/132096-hibernate-user).
