Skip to content

Transaction commit fails with TransientObjectException: persistent instance references an unsaved transient instance  #3712

@tcordel

Description

@tcordel

Hi,

Overview

We met an unexpected error upgrading to spring-boot 3.4.0

I'm not sure this bug deals with spring-data, but i have not been able to reproduce the default using hibernate directly ; maybe you may provide new directions of investigations...

Here is a sample project representing the default with the minimal configuration needed to reproduce it : https://github.com/tcordel/jpa-named-query/tree/main

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientObjectException: persistent instance references an unsaved transient instance of 'com.example.demo.entities.UserNotifEntity' (save the transient instance before flushing)
   	at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:368)
   	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:246)
   	at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:566)

Details

This issue appears only if the optional fetch is done here : NotificationService

Entities

classDiagram
    class ApplicationEntity {
          
    }
    class UserEntity {

    }
    class TypeNotificationEntity{

    }
    class UserNotifEntity {
        +UserEntity User
        +TypeNotificationEntity typeNotif
    }
    class UserNotifAppliEntity {
        +UserNotifEntity UserNotif
        +ApplicationEntity application
    }
Loading

Tests

List of the tests present in DemoApplicationTests :

Thanks for your time :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions