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 6663003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:27:06+00:00 2026-05-26T02:27:06+00:00

Why isn’t my CascadeType.REFRESH actually refreshing my entities? When adding an object it doesn’t

  • 0

Why isn’t my CascadeType.REFRESH actually refreshing my entities? When adding an object it doesn’t update the collection (still empty).

I need to explicit call entity.refresh()! Here’s my partial code (where .ALL could be replaced with .REFRESH, .PERSIST):

@Entity
public class Event extends Model {
    @OneToMany(mappedBy="event", cascade=CascadeType.ALL)
    public List<Invitation> invitations;
}

@Entity
public class Invitation extends Model 
{
    @ManyToOne(cascade=CascadeType.ALL)
    public Event event;
}


// ..
        Event event = new Event(/* ... */);
        event.save();

        if (invitationid > 0)
        {
            Logger.info("Invitation added to event");
            Invitation invite = Invitation.findById(invitationid);
                invite.event = event;
                invite.save();
        }

        // Explicit calling this, will actually do refresh the object and show the invite.
        // event.refresh();

        if (event.invitations == null || event.invitations.size() == 0)
            Logger.info("Still null?!");
// ..

I’m Play! framework which seems to be shipped with hibernate-jpa-2.0.

  • 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-26T02:27:06+00:00Added an answer on May 26, 2026 at 2:27 am

    You are responsible of the coherence of the object graph. JPA won’t automatically add a child to a parent’s collection when you save the child. It’s thus of your responsibility to do

    Invitation invitation = new Invitation();
    invitation.setEvent(event);
    event.getInvitations().add(invitation);
    

    It’s even better to encapsulate this in a addInvitation method of the Event class:

    public void addInvitation(invitation) {
        this.invitations.add(invitation);
        invitation.setEvent(this);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why isn't Collection.remove(Object o) generic? Seems like Collection<E> could have boolean remove(E o); Then,
Isn't there a Design Pattern who describes how to high cohesion? I need some
This isn't legal: public class MyBaseClass { public MyBaseClass() {} public MyBaseClass(object arg) {}
Isn't there some way to re-write the following code, such that I don't need
This isn't working. Can this be done in find? Or do I need to
Isn't there a way where I can refresh the page right after a database
php isn't really my thing but I would need to get the votes and
Isn't the use of delegates to help with some asynchronous cases? I tried the
Isn't there a way with Hibernate to return a list of (primitive) values from
Isn't there a CSS way of having the page to get a border around

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.