Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3320028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:53:39+00:00 2026-05-17T22:53:39+00:00

I have a test suite that needs to delete any existing data in my

  • 0

I have a test suite that needs to delete any existing data in my local MySQL test instance for a large number (but not all) of the tables in the system.

 delete from customer;

Of course, customer has quite a few foreign keys to it, so I also have to delete a few more tables…

 delete from customer_email;
 delete from customer_phone;

And again, these tables have more foreign keys…

 delete from customer_email_notification;
 delete from customer_phone_call;

etc etc ad nauseum. It’s frustrating to have to mentally navigate the entire data model in order to write the test setup.

I am using Hibernate so I was wondering if there was some way to automatically get a priority-order list of tables such that it can be passed directly to a deletion handler. Ideally:

 List<String> dependentTables = foreignKeyGraph.findAll("customer");
 deletionHandler.clean(dependentTables);

Is there a Hibernate utility out there that can do this? I was going to write something that traversed our domain’s annotations and derived table names that way, but it seems like a lot of work for a fairly common problem. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:53:40+00:00Added an answer on May 17, 2026 at 10:53 pm

    A good way to handle this is to use DELETE triggers on each table. On the CUSTOMER table there would be a trigger to delete all the related data found by following each foreign key that relates back to CUSTOMER for the given CUSTOMER_ID – likewise for each table related to CUSTOMER – and each table related to those tables, etc. So for example, if the CUSTOMER_EMAIL table relates back to CUSTOMER via CUSTOMER_ID, and likewise CUSTOMER_PHONE, then the delete trigger on CUSTOMER might look like

    CREATE TRIGGER CUSTOMER_AD  -- AD = After Delete
      AFTER DELETE ON CUSTOMER
      FOR EACH ROW
    BEGIN
      DELETE FROM CUSTOMER_EMAIL E WHERE E.CUSTOMER_ID = :NEW.CUSTOMER_ID;
      DELETE FROM CUSTOMER_PHONE P WHERE P.CUSTOMER_ID = :NEW.CUSTOMER_ID;
    END CUSTOMER_AD;
    

    Share and enjoy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Visual Studio 2008 sp1 test suite web test that uploads
I've tryed mylyn but i cant find that feature, if anyone have test mantis
I'm creating an API using Tipfy . I have an existing suite that tests
I have the following layout for my test suite: TestSuite1.cmd: Run my program Check
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have a test environment for a database that I want to reload with
I have a test web service replicating a live web service that hasn't been
I have a 'suite' of VS2005 unit tests that attach a db as part
I have a suite of database unit tests that were created. In order to
Is there any way to pass a variable from the suite to the test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.