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
|