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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:51:19+00:00 2026-06-10T22:51:19+00:00

I have three entities ‘A’, ‘B’, ‘C’: @Entity public class A implements Serializable {

  • 0

I have three entities ‘A’, ‘B’, ‘C’:


@Entity
public class A implements Serializable {
    ... 

    private B b;  

    @OneToOne(mappedBy = "a", fetch = FetchType.LAZY)
    @Cascade({CascadeType.ALL})
    public B getB() {
        return b;
    }

    public void setB(B b) {
        this.b = b;
    } 

    ...
}

@Entity
public class B implements Serializable {
    ...

    private A a;

    @OneToOne(fetch = FetchType.LAZY)
    public A getA() {
         return a;
    }

    public void setA(A a) {
         this.a = a;
    }

    ...

    private Collection<C> cCollection;

    @OneToMany(mappedBy = "b", fetch = FetchType.LAZY)
    public Collection<C> getCCollection() {
        return cCollection;
    }

    public void setCCollection(Collection<C> cCollection) {
        this.cCollection = cCollection;
    }
    ...
}

@Entity
public class C implements Serializable {
    ...

    private B b;
    @ManyToOne(optional = false, fetch = FetchType.LAZY )
    public B getB() {
        return b;
    }

    public void setB(B b) {
        this.b= b;
    }
}

When I update B.cCollection -add or remove C objects- and then refresh object a, I’ll expect these changes affect results of a.getB().getCCollection(), but it never happens and cCollection list won’t be updated. Am I wrong with refresh() operation?

//Adding or removal C objects to/from a.getB().getCCollection()
//Persisting changes
myEM.refresh(a);

(Note: I use hibernate and JPA 2.0. Persisting data in database has no problem and works truly).

  • 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-06-10T22:51:21+00:00Added an answer on June 10, 2026 at 10:51 pm

    you should use merge method instead: http://docs.oracle.com/javaee/5/api/javax/persistence/EntityManager.html

    myEM.merge(a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three entities as follows: public class EntityA { private Long id; //Getters
I have UI automation tests. Tests involve three entities - Data object class -
I have three Doctrine entities: Device, which has a OneToOne relationship with Device\Status, which
I have three Entity Objects. The relationship between these entities is kinda love triangle!
I have Three entities: FeatureValue.php <?php namespace Webmuch\ProductBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** *
Lets say I have a entity model with three entities Item, ItemType and ItemPart.
I have three entities: Country, State and City with the following relationships: When creating
I have three entities: EntityA, EntityB and EntityC connected with to-many relationships. See schema
I have three entities. Author Newspaper Dissertation Newspaper and Dissertation both can have one
I have a case where i have three entities with one-to-many and one-to-many relationships:

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.