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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:22:53+00:00 2026-06-07T00:22:53+00:00

i have an entity Entity1 that have one to many relation with Entity2 as

  • 0

i have an entity Entity1 that have one to many relation with Entity2 as follows:

1- Entity1:

@Entity
@Table(name = "Entity1", catalog = "mydb")
public class Entity1 implements java.io.Serializable {

  @OneToMany(fetch = FetchType.LAZY, mappedBy = "entity1", cascade = javax.persistence.CascadeType.ALL)
  @OrderBy("id")
  private Set<Entity2> collection = new HashSet<Entity2>(
            0);

}

2- Entity2: (equals and hashcode method overridden)

@Entity
@Table(name = "entity2", catalog = "advertisedb")
public class Entity2 implements java.io.Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "pkid", unique = true, nullable = false)
    @Basic(fetch = FetchType.EAGER)
    private long id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "fk_entity1", nullable = false)
    private Entity1 entity1;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "apid", nullable = false)
    private Entity3 entity3;

}

3- Here’s how i am removing the entity from the collection:

    entity1Obj.getEntity2().remove(entity2);
    log.debug("size after remove: "+ entity1Obj.getEntity2().size()); // size decreases correctly, so the entity is removed from the collection
    entity1Dao.updateEntity1(entity1);

4- DAO method:

   public void updateEntity1(Entity1 entity1) {
        getCurrentSession().update(getCurrentSession().merge(entity1));
    }

Problem: what i get in the console, is a select query for the entity2 that should be removed, and no delete query, and nothing is getting deleted.

please advise how to fix this 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-07T00:22:56+00:00Added an answer on June 7, 2026 at 12:22 am

    i replaced cascade = CascadeType.ALL with orphanRemoval = true and it works fine now.

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

Sidebar

Related Questions

I have the below unidirectional Many To One mapping @Entity public class Item implements
here are my models. There's keyInfo in many-to-one relation with userInfo. @Entity @Table(name =
I have a piece of code that adds elements to entity collection (one-to-many relation).
i have a self join employees entity class with id,name and ref columns that
I have two entities, Entity1 and Entity2, on a one to many relationship. On
I have two Doctrine entities that have a one-to-many relationship, like this: License class
I have many to one relation, let's say User has a Company. Company entity
How would one structure a table for an entity that can have a one
For each entity that has a one to many relation with other entity when
I have a JPA entity class (one of many) and I can run JPQL

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.