-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Remove fails with @ManyToOne aggregation
PostPosted: Mon Jul 27, 2009 6:29 pm 
Newbie

Joined: Mon Jul 27, 2009 6:26 pm
Posts: 1
Hello,

Hibernate 3.3
EntityManager & Annotations 3.4

We have the following entities:

Code:
@Entity
public class A {
  @Id
  private Long id;

  @OneToMany(mappedBy = "a", cascade = ALL, fetch = LAZY)
  @Cascade(DELETE_ORPHAN)
  private List<B> bList = new ArrayList<B>();
}

@Entity
public class B {
  @Id
  private Long id;

  @ManyToOne(cascade = ALL, fetch = EAGER)
  private A a;

  @ManyToOne(fetch = LAZY, optional = false)
  @JoinColumn(name = "C_ID", nullable = false)
  private C c;
}

@Entity
public class C {
  @Id
  private Long id;
}


A -> B is a composition: A is the owner of all Bs.
B -> C is an aggregation: Cs can exist without Bs, however each B cannot exist without a C

In one use case, we have the following objects which are retrieved from the database: a1 -> {b1} and b1 -> c1. We try to remove c1, then remove b1 from a1:

Code:
entityManager.remove(c1);
a1.remove(b1);


Whatever we try, the EntityManager tries to set b1.c to null before deleting it. It seems to me that deleting b1 and then deleting c1 would work. Why is the EntityManager not doing this?

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.