-->
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: @OnDelete
PostPosted: Fri Jun 21, 2013 2:10 pm 
Newbie

Joined: Wed Feb 27, 2013 2:59 pm
Posts: 6
Hi, I am trying to understand the OnDelete annotation.
I have a Order class and a OrderItem class....
So far, I understand that if I use the OnDelete annotation on a child object, child objects will be deleted when the parent is deleted.

On a order item...

Code:
@ManyToOne(targetEntity = OrderEnt.class, fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "order_id", nullable = false)
@ForeignKey(name = "fk_order")
@OnDelete(action = OnDeleteAction.CASCADE)
@Valid
@NotNull
private OrderEnt order;;


this will create DDL containing
Code:
CONSTRAINT fk_order FOREIGN KEY (order_id)
REFERENCES orders (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE,


But in the order object I have...
Code:
@OneToMany(targetEntity = OrderItemEnt.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "order")
@OnDelete(action = OnDeleteAction.CASCADE)
@OrderBy("id asc")
@Valid
private Set<OrderItemEnt> orderItems = new HashSet<OrderItemEnt>();


What effect does the @OnDelete(action = OnDeleteAction.CASCADE) have here ???


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.