remove « Map « JPA Q&A

1. How to remove entity with ManyToMany relationship in JPA (and corresponding join table rows)?

Let's say I have two entities Group and User. Evety user can vbe member of many groups and every group can have many users.

public class User {

2. Hibernate cannot remove child from database

Here is my situation: I load an object that contains a bi-directional parent child relationship into my database. Later, that object is loaded into my UI where changes can be made, ...

3. Hibernate: How to remove an entity to which none refers to anymore in ManyToOne?

I have two entities, lets call them A and B, which have a ManyToOne mapping to another entity, say C So I typically have something like this: a1->c a2->c b1->c Lots of A's and B's pointing ...

4. Best practice when removing entity regarding mappedBy collections?

I'm still kind of undecided which is the best practice to handle em.remove(entity) with this entity being in several collections mapped using mappedBy in JPA. Consider an entity like a Property that ...

5. Removing parent and all children

I have a problem removing the parent entity from the database. The code looks like this:

public class Parent implements Serializable {
  @GeneratedValue(strategy = GenerationType.TABLE)
  private Long id; ...

6. NHibernate: Removing child from many-to-many relationship causes exception

I've been battling with this issue for a couple of days now. I have a couple of classes in a many-to-many relationship, configured like so:

<class name="Entry" table="Entries">
    <id name="Id" ...

7. JPA: When parent entity got removed, child entity still remain

Customer Entity (Parent Entity)

public class Customer {

@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;

@OneToMany(mappedBy="customer", cascade=CascadeType.ALL)
private List<Facility> facilities;

//Setter and Getter for name and facilities

public void addFacility(Facility facility){
    if(this.facilities == null){

8. how to remove one-to-many child from parent given the child id in HQL

I've got

class Parent
    IList<Child> Children;

class Child
When deleting a Child I need to remove all references to it from any Parents that reference it. How can I do this in ...

9. ManyToMany remove problem

I have a table: DocumentType:

 @ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY)
   name = "document_type_property_type",
   joinColumns = @JoinColumn(name = "document_type"),
   inverseJoinColumns = @JoinColumn(name ...

10. Hibernate query:Don't delete child when removing association with parent

I am removing a Child from its association(many to one) to Parent.When i use saveOrUpdate method on Parent, Hibernate by default tries to remove Child from the Table.Is it a bug ...

11. hibernate doesn't remove child with named query, but removes with session.delete()

I am not an expert with hibernate, as stated in the subject, I have an Object with a Collection of object in it. I tried to use a

and the entity ...

12. How to write Hibernate HQL query which remove all "grand children" elements?

I have schools, which contains groups, which contains students. I would like to remove all students from specific school. In SQL I can write the following query:

DELETE FROM students1 
WHERE students1.group_id IN 

13. JPA relationship not getting updated when children are removed

Given the following scenario:

public class A {
  @OneToMany(mappedBy = "a", cascade = CascadeType.ALL)
  private List<B> bList;

public class B {
  @JoinColumn(name = "a_id", referencedColumnName = "id")

14. How to remove a many-to-many association in Hibernate without actually deleting Objects

I have 2 Hibernate classes in a Spring-driven Application like these:

public class Image {

@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

@ManyToMany(mappedBy = "picture", fetch = FetchType.LAZY)
private Set<InspectionObjectDetail> inspectionObjectDetails = new HashSet<InspectionObjectDetail>();

public int hashCode() {

16. Save/remove children through parrent collection

Hi, i am writing a piece of logic which would save/remove attachments to an action. Frontend displays all possible attachments for this action and then the user has to select which attachment to save with that action. Selected attachments are saved in a different entity. Upper layer provides me with a map of attachments (Map -> second parameter mean attachment ...

17. Removing Child object from DB

I've just ran into a problem (well for me anyway). I have a class called Department which has a collection of TradingAccounts(). This all persists OK in the database. My problem occurs when I delete one of the items from this collection. Although my Collection of TradingAccounts no longer has a reference to it, it remains in the database!. I've read ...

18. Remove mapped class from the configuration.

I am writing for my diploma thesis an aspect oriented persistence layer. I use Hibernate for the persistence layer and add aspects to it. My goal is that the programmer only need to declare a java object as persistent. Other things such as mapping and database access code will be automaticaly added from the aspects. The problem I have now is ...

20. removing value from Map collection doesn't update database

Hibernate version: 2.1.7 Mapping documents: ... Code between sessionFactory.openSession() and session.close(): session.beginTransaction(); ... Folder folder = session.get(...); ... folder.getAttributes().remove("abc");; transaction.commit(); This snip is from a webapplication we're writing where for each http request a session ...

21. update instead of delete when removing a child from parent

Beginner Joined: Thu Jun 17, 2004 10:08 am Posts: 21 Location: Paris-France Hi, Before all, thanks for you attention :)) ! I'm using hibernate2.1 with Oracle9 and my program is a stand alone application. My problem: So, i have 2 objects: TransoraDetail and TransoraAddModifyDetail; The relationschip betwen the 2 objects it's one to multi (unidirectionel); a TransoraDetail can have one or ...

22. Update parent in one-to-many doesn't delete removed children

I am having trouble with a parent-child relationship. Specifically dealing with children not being deleted from the DB when they are removed from the parent's collection. The mappings shown below work when I delete the parent (ie. the children are deleted from the DB as well), but on an update, the removed child is never deleted from the DB. Hibernate version: ...

23. hibernate stucks after adding/removing a mapping property

Author Message MistaMoasn Post subject: hibernate stucks after adding/removing a mapping property Posted: Tue Jun 28, 2005 9:22 am Beginner Joined: Mon Jun 06, 2005 4:23 am Posts: 41 Location: Hagenberg, AUSTRIA regarding to my hibernate tools post i got the same problem without using the hibernate tools. hibernate stucks during execution of my application code, too. steps ...

24. Problem removing child object from collection after saving

Hi, I'm having problems removing a child object from a collection immediately right after saving it. The use case that fails for me is as follows: 1. I load the parent with all the existing children. 2. I add a new child. 3. I call saveOrUpdate. 4. New child appears on the database and is given a generated primary key. 5. ...

25. Replicate not removing children

Newbie Joined: Mon Oct 10, 2005 8:33 pm Posts: 2 I poked around a bit, but couldn't find an answer to the question I have. I have an entity that involves a one-to-many relationship - an order is the parent, and an order can be served by multiple shipments. This entity is stored in two separate databases. One database is the ...

26. One to one mapping and remove...

27. Child object is not deleted when removed from collection

Author Message patrick.wilkes Post subject: Child object is not deleted when removed from collection Posted: Wed Jan 18, 2006 8:02 pm Newbie Joined: Wed Jan 18, 2006 7:30 pm Posts: 4 I have a problem working with detached objects, in that in certain circumstances child objects (in collections) that should be removed are not being removed when the detached ...

28. Removing and Updating Childs in HashSet

Author Message Sukumesh Post subject: Removing and Updating Childs in HashSet Posted: Tue Mar 14, 2006 3:32 am Newbie Joined: Tue Mar 14, 2006 2:36 am Posts: 1 HI all, I am getting Constraint Violations while doing this. 1. I am retriving Master Object from DB 2. Removing Childs from the Master Object 3. Adding New child objects To ...

29. children not removed from db when removed from collection

Beginner Joined: Fri Oct 27, 2006 3:35 pm Posts: 21 Hi Folks, I'll apologise now if this question has an obvious answer, but I've been stumped for days now even after trawling this forum and other online examples... I've got a fairly typical 'user' / 'basket' / 'basket item' arrangement for an online shop. Each User has exactly 1 Basket, and ...

30. Change the parent of an child entity without remove

Hi, I have a 1:N association. For example a customer class 1 and order class N and the order have also childs order class 1 and adress class N in hibernate this is realized with a collections. Ok, how can I change the parent of the class order to another customer. When I use remove and use "all-delete-orphan" ,hibernate removes me ...

31. Removing an Entity in ManyToMany reflexive relationships.

Newbie Joined: Wed Jun 13, 2007 5:44 am Posts: 16 Hi, I'm using Jboss 4.0.5 and Seam 1.2.1 and I'm getting some problem with the EntityManager, trying to remove some Entities. Here's the point. I have an Entity, called Topic, which have a ManyToMany relationship to itself. I decided, regarding my application, to store both children and parents in an entity, ...

33. Urgent help, removing child entity from parent Home object

Newbie Joined: Tue Nov 25, 2008 9:31 pm Posts: 18 I have entities with realtionship like : -Project entity can have multiple QuantExperiments. -QuantExperiment entity can have multiple Reagents and -Reagent entity can have multiple Treatments. We have a functionality where user clicks a link to remove reagent from QuantExperimentEdit.xhtml. Clicking on "Remove Reagent" removes particular row from ui. But when ...

34. Please help, removing child entity from parent Home object

I have entities with realtionship like : -Project entity can have multiple QuantExperiments. -QuantExperiment entity can have multiple Reagents and -Reagent entity can have multiple Treatments. We have a functionality where user clicks a link to remove reagent from QuantExperimentEdit.xhtml. Clicking on "Remove Reagent" removes particular row from ui. But when I click "Update Experiment", it removes ALL treatments, ALL reagents, ...

35. Many-to-Many mapping on Set dosnot remove the elements

Page 1 of 1 [ 1 post ] Previous topic | Next topic Author Message gnandigam Post subject: Many-to-Many mapping on Set dosnot remove the elements Posted: Tue Feb 10, 2009 10:04 pm Newbie Joined: Tue Feb 10, 2009 9:48 pm Posts: 1 Hi, I have a User , and UserGroup ...