Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: OnDelete Cascade on JPA with annotations only (DB2Dialect)
PostPosted: Wed Jun 29, 2011 12:08 pm 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
Hello,

I have red all JPA OnDelete forum threads, but these are not finished with a solution.

I want to test DELETE CASCADE on DBMS side with JPA and annotations only an got problems.

I have a class Items that has Many Item elements :
@org.hibernate.annotations.Fetch(value = org.hibernate.annotations.FetchMode.SUBSELECT)
@org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
@org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
@OneToMany(targetEntity = com.Item.class, cascade = { CascadeType.ALL}, fetch = FetchType.EAGER)
@JoinColumn(name = "ITEM_ITEMS_BOOBJECTID")
public List<com.Item> getItem() {
if (item == null) {
item = new ArrayList<com.Item>();
}
return this.item;
}

Dont worry about twice annotations like fetchmode. I had to overwrite fetchmode with hibernate annotations because the base code is generated with hyperjaxB...

When hibernate starts its entityManager the following exception is thrown:
Can not create persistence entity manager
only inverse one-to-many associations may use on-delete="cascade": com.Items.item

Here is my problem. Actually JPA has no bidirectional mapping, so I cannot map child to partent with inverse= true.
Therefore I have no hbm file so I cannot set OnDelete at the <Key> element.

I am running hibernate 3.5.6-Final.

- Is my annotation configuration correct ? (Should cascadeType.ALL may be replaced by every operation except Remove ? )
- Should I update hibernate so that OnDelete is supported with unidirectional mapping ?

really thanks for advises.


Regards, Andre, Berlin


Top
 Profile  
 
 Post subject: Re: OnDelete Cascade on JPA with annotations only (DB2Dialect)
PostPosted: Thu Jun 30, 2011 5:30 am 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
I've tested hibernate 3.6.5. The same error occurs.

I think this is not jet implemented in hibernate due missing JPA specification.
For the further JPA process, I think OnDelete=CascadeDelete must be possible together with OrphanRemoval=tue on unidirectiona OneToMany,
because OrphanRemoval=tue is for Updates and OnDelete=CascadeDelete is for deletes.

In hope that the JPA working group will reach that target.

(may an hibernate team official can comment that)

rgs Andre


Top
 Profile  
 
 Post subject: Re: OnDelete Cascade on JPA with annotations only (DB2Dialect)
PostPosted: Thu Jun 30, 2011 5:39 am 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
related forum thread:
viewtopic.php?f=1&t=1011065&p=2446488&hilit=JPA+OnDelete#p2446488

related JIRA issue:
http://opensource.atlassian.com/project ... e/HHH-6382


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

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.