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 6062729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:05:07+00:00 2026-05-23T09:05:07+00:00

Let me get my question straight, using the @OnDelete here will delete this and

  • 0

Let me get my question straight, using the @OnDelete here will delete this and any other InventoryPreference entities if the Inventory entity is deleted? I just can’t understand a thing from Hibernate’s annotations reference.. so I need your help to confirm that I understood it correctly.

public class InventoryPreference {
    ...

    @ManyToOne
    @OnDelete(action = OnDeleteAction.CASCADE)
    @JoinColumn(name = "inventory_id", nullable = false)
    public Inventory getInventory() {
        return inventory;
    }
}

Do I then in the Inventory entity need to use CascadeType.ALL too to get all the InventoryPreferences deleted if the Inventory entity is deleted?

public class Inventory {
    ...

    @OneToMany(mappedBy = "inventory", cascade = CascadeType.ALL)
    public Set<InventoryPreference> getPreferenceItems() {
        return preferenceItems;
    }
}

If the first question is true, then I don’t see the point of CascadeType.ALL. If it’s not then what do each of these do and what annotations and configuration I need to specify to get the InventoryPreferences deleted when Inventory is deleted? Oh and I don’t want the Inventory to be deleted if InventoryPreference gets deleted. Sorry if it’s too obvious.

  • 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-23T09:05:07+00:00Added an answer on May 23, 2026 at 9:05 am

    They do somewhat different things. @OnDelete is a schema generation instruction. It will add ‘on delete cascade’ to the end of the DDL generated for the foreign key (or dialect equivalent.) If you’re not using hibernate to generate your database, it isn’t going to do anything.

    The cascade property on the @OneToMany or @ManyToOne is what’s used at runtime to generate additional actual SQL statements. That’s probably what you actually want, additional delete statements to remove the children, not delete cascades turned on in the database table? If what you want is for InventoryPreferences to get removed when you delete an Inventory, then you want:

    @OneToMany(mappedBy = "inventory", cascade = CascadeType.REMOVE, orphanRemoval=true)
    public Set<InventoryPreference> getPreferenceItems() {
        return preferenceItems;
    }
    

    And of course add additional Cascade Types as appropriate to your design.

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

Sidebar

Related Questions

Let's get straight to my question: I have a socket and all input coming
First, let's get the security considerations out of the way. I'm using simple authentication
Let me describe the behavior I get: Load a user from the database: this
I usually get so confused with UML and this situation is no different. Let's
Okay, so this is a straight math question and I read up on meta
Caveats: Let me first clarify that this is not a question about whether to
This should be simple. Question How do you get a pointcut in one project
Let me get straight to the point :). In my project I'm rendering an
this is my first question here @stackoverflow. I'm writing a monitoring tool for some
quick question I know in wordpress you can get post_content,etc but let say I

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.