-->
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.  [ 5 posts ] 
Author Message
 Post subject: Best way to delete data in a table?
PostPosted: Sat Sep 06, 2003 4:57 am 
Newbie

Joined: Fri Aug 29, 2003 10:14 pm
Posts: 3
I have two tables A & B. A has a one-to-many relationship with B, and also keeps a many-to-one relationship to record the last B element. B keeps a many-to-one reference back to A as the parent entity.

A
id = 1
lastB = 2

B
id = 2
A = 1

As part of my test environment, I have an InitDB.java script, that calls session.delete() and then initializes the database.

When I use session.delete("from B in " + B.class); I get the flush/cascade error.

Two things I have questions on:

1) I'd like to know how to get the constraint set up so that when the row in B is deleted, it automatically sets A.lastB to null

2) Is using session.delete("...") the best way to delete an entire database? Or should I just keep dropping/recreating tables from a .sql file like I'm doing today?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 8:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Don't use Hibernate (or any other ORM solution, probably) for mass updates/deletes. Thats not what ORM is really _for_.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 9:41 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 2:50 pm
Posts: 45
Location: US: New York NY
Refer to your docs, but this should work with PostgreSQL
ALTER TABLE a
ADD ( FOREIGN KEY (lastB)
REFERENCES b (id) ON DELETE SET NULL) ;


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 4:09 pm 
Newbie

Joined: Fri Aug 29, 2003 10:14 pm
Posts: 3
Thanks Gavin - I'll move to plain JDBC calls in the initialize script.

Thanks Russell - this is what I was looking for. Now, I use xdoclet tags to generate my mapping files (.hbm) and the SQL schema (SchemaExport). Is there any way to specify using hibernate and/or xdoclet that the 'on delete set null' be added to the generated alter table ... references statement?

Or would I need to make changes to the PostgreSqlDialect?


Top
 Profile  
 
 Post subject: on delete set null ins many-to-one relationship
PostPosted: Thu Dec 23, 2004 8:42 am 
Newbie

Joined: Thu Nov 25, 2004 6:43 am
Posts: 2
Hi,

although this thread died quite a long time ago I'll ask again:
is there a way to specify ON DELETE SET NULL constraint for many-to-one relationship in the mapping file?

Thanks for any reply,
julius


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.