Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:55:19+00:00 2026-05-30T19:55:19+00:00

I know this question has been asked numerous times but I couldn’t find a

  • 0

I know this question has been asked numerous times but I couldn’t find a suiting answer for me.

I’ve got two entities in a Spring Roo-application which are in a Many-To-Many-relationship, Release and Component.

First I fetch an instance of an existing Release via

selectedRelease = Release.findReleasesByReleaseNumberEquals(version).getSingleResult();

The method above is a Roo-generated finder which looks like this:

public static TypedQuery<Release> Release.findReleasesByReleaseNummerEquals(String releaseNumber) {
    EntityManager em = Release.entityManager();
    TypedQuery<Release> q = em.createQuery("SELECT o FROM Release AS o WHERE LOWER(o.releaseNumber) LIKE LOWER(:releaseNummer)", Release.class);
    q.setParameter("releaseNumber", releaseNumber);
    return q;
}

Then I create a new instance of Component and try to assign it to the selected Release

Component component = new Component();

Set<Release> releases = new HashSet<Release>();
releases.add(selectedRelease);

component.setReleases(releases);
component.persist();

Upon trying to execute persist() I get the exception:

TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: com.Release;

Does anyone have advice regarding this problem?

The mappings look like this:

Release.java:

@ManyToMany(cascade = CascadeType.PERSIST, mappedBy = "releases")
private Set<Component> components = new HashSet<Component>();

Component.java

@ManyToMany(cascade=CascadeType.PERSIST)
private Set<Release> releases = new HashSet<Release>();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:55:20+00:00Added an answer on May 30, 2026 at 7:55 pm

    The message is clear: you are trying to save an object, component, that references another object that hasn’t been saved yet, selectedRelease.

    The solution seems to be easy: just save (and flush whenever you want the changes be comunicated to the database) the Release objects before saving the Component.

    However, JPA allows you to avoid all these sentences with TRANSITIVE PERSISTENCE, that is, the cascade options in the @…ToMany annotations.

    Just a warning in case you have a bidirectional relationship, when you have a mappedBy attribute in one of the @…ToMany associations. In this case, you’ll need a convenient method to manage the association, that is, to set both sides of the association.

    For instance, an addRelease(Release r) in Component that both adds the release to the component’s set, and sets the component (actually, the this instance) to the release passed as parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked many times before but I can't find
I know this question has been asked so many times before but I couldn't
I know this question has been asked before but I really couldn't find anything
I know this question has been asked before numorous times but they seem to
I know this question has been asked countless of times. But none of them
I know this question has been asked numerous number of times, both here and
I know this question has been asked several times, but I can't quite seem
I know this question has been asked a couple of times, but there's something
I know this question has been asked many times, but I am having trouble
I know this question has been asked multiple times but all the answers seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.