-->
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: problem with database level cascade delete
PostPosted: Thu May 21, 2009 12:04 pm 
Newbie

Joined: Thu May 21, 2009 11:48 am
Posts: 1
I'm having trouble with the hibernate @OnDelete annotation to generate a database level cascade delete constraint using ant HibernateToolTask on a @OneToMany relationship, and i'm beginning to go square eyed trying to fix this

Using Hibernate Annotations 3.4.0, connecting to an Oracle 11g Database, using the org.hibernate.dialect.Oracle10gDialect.

I've specified a one way relationship from the Parent to the Child as follows
Code:
@OneToMany
@ForeignKey(name = "FK_NAME")
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "JOIN_COLUMN_ID", nullable = false)
public Set<Children> getChildren() {
   return children;
}


This sucesfully procduces an alter table statement adding the casacde delete constraint and when manually inserting and generating data in the db and performing deltes this works. However, upon starting tomcat, and initialising hibernate i get the following error:
only inverse one-to-many associations may use on-delete="cascade":

So, I've tried creating a bi-directional relationship as follows
Code:
@OneToMany( mappedBy = "parent" )
public Set<Children> getChildren() {
   return children;
}

and on the Child class
Code:
@ManyToOne
@ForeignKey(name = "FK_NAME")
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "JOIN_COLUMN_ID", nullable = false)
public Parent getParent(){
        return parent;
}


This version doesn't generate the cascade delete on the foreign key, but also doesn't generate the error upon initialising hibernate.

I've even tried putting @OnDelete both relationships, which causes the foreign key constraint to be added and the error to appear.

Is there any way, or something really simple that i'm missing, to get hibernate to generate the cascade constraint when generating the sql statements, but not to throw the MappingException?

I've seen this question come up on the forums a few times without any answer, so i'm hoping there's some really obvious simple solution that i'm just not seeing at the moment.


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.