Skip to content

"Exception : could not re-associate uninitialized transient collection" #3768

@siwan9

Description

@siwan9
  • environment
    • java 17
    • 'org.springframework.boot' version '3.2.4'

Hello 👋

If the comment entity is deleted in the presence of 'users', 'posts', 'comments', 'notifications', and 'notifications_users'(notification target user) entities, I want to use the @PreRemove annotation to delete notifications related to comments.
The following photo shows the code implementing @PreRemove.

Image

Key entity structures and relationships between entities are as follows.

  • posts
    Image

  • comments
    Image

  • notifications
    Image

  • notifications_users
    Image

  • The notification table does not have a foreign key relationship with the notification generation subject table, but has the notification generation subject table id as a normal key invoker_id, and has the type of notification generation subject table as an invoker_type column.
    When a comment is generated, a notification is generated for comment-related users.

  • The notifications_users table is a table that connects the notification table and the user table many times.

In the situation of deleting one comment, notification related to the comment and deletion of the notification target user entity through cascade proceeded without any problems.
However, in the context of deleting the post, the comments were deleted through cascade and the exception specified in the title was returned in the deletion logic of the notification target user and notification through @PreRemove.

Rather than the exception being returned directly from the logic of accessing @PreRemove and deleting the notification, we have repeatedly confirmed that some requests go well, but if you approach the Daetagle, that exception is returned.

  • table data record

    • comments data
      Image
    • notifications data
      Image
    • notifications_users data
      Image
  • flow

    • controller(request : recruitmentBoardId=19)
      Image
    • service
      Image
  • log
    Image

Image

  • '호출' is calling method. and '성공' is method success

  • A query that inquires about the first target post to be deleted and the comments related to Cascade is executed, and the comments are deleted while touring the searched comment list.
    Since the first comment is a comment with id number 4 (see comment table data among the pictures attached above), the PreRemove method runs before deleting comment number 4.
    The method is configured to run a deletion query if a notification exists after querying the target notification to be deleted (see EntityListener photo attached for the first time)
    There is no notification until number 11, so there is no other action.
    In comment preremove 12, all comments to be deleted that have been checked in the past are suddenly deleted, and notification related to comment 11 and notification target users are deleted.
    Running the Notification Lookup Method in Comment 13 PreRemove findByInvokerIdAndInvokerType will cause an exception.

  • additional test

  • PreRemove Method
    Image

  • log
    Image

  • Description

    • As a result of changing to the corresponding PreRemove method, the following exception occurred in the findByInvokerId method subject to the notification3 variable in comment 12 PreRemove.

We checked whether the transaction was forced to end and active, but we confirmed that they all received True and consistently had the same transaction object.

I've been thinking about debugging for a long time, but I can't think of the cause and solution of the exception, so I'd like to ask you through the issue.
Please help me

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.com

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions