-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: SchemaExporter cascade references
PostPosted: Wed Oct 29, 2003 4:02 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

I'm using SchemaExporter to create a DDL for a mySQL database with InnoDB databases.

In the maping files I have mapped an array with cascade="all" atributte, but there is no reference in the DDL SQL script.

<class name="DocsFolder" ...

<array name="folder" table="Array_DocsFolder" cascade="delete">
<key column="chve1"/>
<index column="i"/>
<many-to-many column="chve2" class="DocsFolder"/>
</array>

<class>

alter table DocsFolder add index (subChvp), add constraint FKFDBC8D769098A83F foreign key (subChvp) references DocsElement (chvp)

alter table Array_XeDocsFolder add index (chve2), add constraint FK95F799BC5A424DE foreign key (chve2) references DocsFolder (subChvp)

alter table Array_XeDocsFolder add index (chve1), add constraint FK95F799BC5A424DD foreign key (chve1) references DocsFolder (subChvp)


What am i doing wrong?

Thanks again,
Joao Rangel


Top
 Profile  
 
 Post subject: Same Problem...
PostPosted: Thu Oct 30, 2003 6:37 am 
Newbie

Joined: Thu Oct 30, 2003 6:31 am
Posts: 8
Hi...

I'm new wih the hibernate and I have the same problem.

If someone can help thanks.

HS


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 6:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The "cascade" is an attribute used by Hibernate at runtime for association management, it is not used to generate foreign key constraint options.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: But...
PostPosted: Thu Oct 30, 2003 6:49 am 
Newbie

Joined: Thu Oct 30, 2003 6:31 am
Posts: 8
Ok,

but when I try to delete a row from a table, I get this problem....

General error, message from server: "Cannot delete or update a parent row: a foreign key constraint fails"

It's a objec (table) that contains an array whith object's from the same type,

Thanks


Top
 Profile  
 
 Post subject: Again
PostPosted: Thu Oct 30, 2003 7:07 am 
Newbie

Joined: Thu Oct 30, 2003 6:31 am
Posts: 8
There is any way to skirt this "problem" ??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 7:08 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't understand what you are talking about. How is this problem Hibernate related? You can't delete rows in a table if theres a foreign key constraint on that row.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: But...
PostPosted: Thu Oct 30, 2003 7:15 am 
Newbie

Joined: Thu Oct 30, 2003 6:31 am
Posts: 8
But if the foreign keys have the :
references (field) + ON DELETE CASCADE

that shuld be possible rigth?

Is that i want.
There is any way to do that?

Thans
HS


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 7:20 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
AFAIK, Hibernate can't generate these FK constraint options, so you have to alter the constraint manually after DDL creation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Thu Oct 30, 2003 7:23 am 
Newbie

Joined: Thu Oct 30, 2003 6:31 am
Posts: 8
Ok...
Thanks.

I will try.

HS


Top
 Profile  
 
 Post subject: deleting the referenciator object
PostPosted: Fri Oct 31, 2003 11:00 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

I have a problem with object references that i would like to ask:

Imagine that I have class A and B, and A has a reference to B.
If i delete object A with cascade=all option, object B is deleted too.
But if i delete object B, in the same conditions, Objet A is not deleted and i get an exception:

java.sql.BatchUpdateException: General error, message from server: "Cannot delete or update a parent row: a foreign key constraint fails"


How can i solve this problem?

Thanks,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 11:08 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This means B has a reference to A (or to an other object) and need to be set to cascade="all" too

_________________
Emmanuel


Top
 Profile  
 
 Post subject: But....
PostPosted: Fri Oct 31, 2003 11:17 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
If i do that, when i'll try to delete B, he will try to delete A, which refers B. That will cause a loop. Right?


Top
 Profile  
 
 Post subject: BAD but soluction
PostPosted: Fri Oct 31, 2003 11:46 am 
Newbie

Joined: Thu Oct 30, 2003 6:31 am
Posts: 8
I have a "bad" but soluction for that.

I have re-generate all references build from hibernate and I put there "ON DELETE CASCADE", "ON DELETE SET NULL"...

I haven't find in hibernate way to do that.

I hope thats help


Top
 Profile  
 
 Post subject: Re: But....
PostPosted: Fri Oct 31, 2003 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
jpgr wrote:
If i do that, when i'll try to delete B, he will try to delete A, which refers B. That will cause a loop. Right?

Do you mean an infinite loop ? No. Hibernate isn't that stupid.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Ok
PostPosted: Fri Oct 31, 2003 12:31 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
ok, you are teelling me that hibernate detects loops... But since i have a uni directional relantion, it doesn't make sense to have a bidirectional mapping.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.