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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:33:35+00:00 2026-06-04T17:33:35+00:00

i have the following entity relationship: SideA: @Entity @Table(name = SideA) public class SideA

  • 0

i have the following entity relationship:
SideA:

@Entity
@Table(name = "SideA")
    public class SideA {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long  id;

    @CascadeOnDelete
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "sideA", cascade=CascadeType.ALL)
    private List<ABAssociation> association = new ArrayList<ABAssociation>();
}

Side B:

@Entity
@Table(name = "SideB")
public class SideB {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long  id;

    @CascadeOnDelete
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "sideB", cascade=CascadeType.ALL)
    private List<ABAssociation> association = new ArrayList<ABAssociation>();
}

ABAssociation:

@Entity
@Table(name = "ABAssociation")
public class ABAssociation {

   @EmbeddedId
   private ABAssociationPK pk = new ABAssociationPK();
   @ManyToOne(cascade=CascadeType.MERGE)
   @MapsId("aId")
   private SideA sideA;

   @ManyToOne(cascade=CascadeType.MERGE)
   @MapsId("bId")
   private SideB sideB;
}

ABAssociationPK:

@Embeddable
public class ABAssociationPK implements java.io.Serializable{
    private long aId;
    private long bId;
}

my problem is when i delete one side, the database delete the row in ABAssociation , but still stay in cache.

test code is like the follow:

SideA a = new SideA();
SideB b = new SideB();
entitymanager.persist(a);
entitymanager.persist(b);

ABAssociation ab = new ABAssociation()
ab.setSideA(a);
ab.setSideB(b);
entitymanager.persist(ab);

a.getABAssociationList().add(ab);
b.getABAssociationList().add(ab);

a = entitymanager.merge(a);
b = entitymanager.merge(b);

entitymanager.delete(a);

Since “a” was deleted, the relationship between “a” and “b” should be deleted too.
but when i check the “b.getABAssociationList().size()” it still there, even there is no rows in ABAssociation table in DB.

it this related to the share cache issue ?

  • 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-04T17:33:37+00:00Added an answer on June 4, 2026 at 5:33 pm

    In JPA you must maintain you object’s relationships.

    If you remove an object, you must first remove all references to it.

    See,
    http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Object_corruption.2C_one_side_of_the_relationship_is_not_updated_after_updating_the_other_side

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

Sidebar

Related Questions

Say, I have following entities: @Entity public class A { @Id @GeneratedValue private Long
I'm using jpa and I have the following entity: @Entity @Table(name=favorites_folders) public class FavoritesFolder
I have the following mapping: @Entity @Table(name = Prequalifications) public class Prequalification implements Serializable
Suppose I have the following entities: @Entity @Table(name = A) public class A implements
I have the following 2 entities: @Entity(name = Employee) @Table(name = EMPLOYEE) public class
I have a parent-child relationship: @Entity @Table(name = user) public final class User {
I have the following entities: @Entity public class Owner{ @Id @Column(name = OWNER_ID) @OneToMany()
Let's assume I have defined the following Entity: @Entity class User{ @Id @GeneratedValue @Column(name
I have the following annotated Hibernate entity classes: @Entity public class Cat { @Column(name
Say I have a unidirectional @ManyToOne relationship like the following: @Entity public class Parent

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.