-->
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: Deleting entities with cylcic reference
PostPosted: Fri Apr 20, 2012 8:29 am 
Beginner
Beginner

Joined: Fri Nov 14, 2008 7:11 am
Posts: 31
I have a mapping with three entity classes that have a cyclic reference:

Code:
class A {
    @OneToMany
    @Cascade (value=CascadeType.ALL)
    B b;
}

class B {
    @OneToOne(optional=false)
    C c
}

class C {
    @OneToOne(optional=false)
    A a;
}


So an A can have many B's which have one C's each. C has a reference to his A.

Now I want to delete an entity of type A with its B's and C's. If I use session.delete(a) the B's get deleted by cascade, but the C's don't. Therefore I have to delete the C's by session.delete(c), but now the cyclic reference is a problem as I cannot delete A (C needs it) and also not C (B needs it). I am getting an PropertyValueException (C.a is referencing a null or transient value).

My solution now is to make the reference from C -> A to optional=true so that I can delete A (with B's by cascade) first and C's at the end.

Is their another solution without making the reference optional (as it is only null within this delete transaction)?

EDIT: Adding a delete cascade from B to C is no possible option in my case.

Thanks in advance,
Olel


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.