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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:25:12+00:00 2026-05-16T07:25:12+00:00

I have some problem with @OneToMany and @ManyToOne annotations. I have two class Suite

  • 0

I have some problem with @OneToMany and @ManyToOne annotations.

I have two class Suite and SuiteVersion. A SuiteVersion is dependent of a suite. So i have implemented this in my code:

Class Suite :

@OneToMany(mappedBy = "suite")
@Cascade(CascadeType.DELETE_ORPHAN)
private List<SuiteVersion> listSuiteVersion = new ArrayList<SuiteVersion>();

Class SuiteVersion :

@ManyToOne()
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
private Suite suite;

But i have some problem when i delete a Suite whose have SuiteVersion associated.
Hibernate don’t delete SuiteVersion before Suite.I don’t know why because i have mentioned this in my code :

@Cascade(CascadeType.DELETE_ORPHAN)

This the log i obtained when i delete suite :

Hibernate: delete from SUITE where ID_SUITE=?
13 août 2010 09:40:50 org.hibernate.util.JDBCExceptionReporter logExceptions
ATTENTION: SQL Error: -8, SQLState: 23504
13 août 2010 09:40:50 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: integrity constraint violation: foreign key no action; FK42895651EA304E6 table: SUITE_VERSION

Thank you in advance for your help.

Best Regards,

Florent,

P.S : Sorry for my english i’m french.

  • 1 1 Answer
  • 2 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-16T07:25:12+00:00Added an answer on May 16, 2026 at 7:25 am

    But i have some problem when i delete a Suite whose have SuiteVersion associated. Hibernate don’t delete SuiteVersion before Suite.

    That’s because you’re NOT cascading the REMOVE operation from Suite to SuiteVersion. To obtain the desired result, you need something like this (assuming you’re using JPA 1.0):

    @OneToMany(mappedBy = "suite", cascade = javax.persistence.CascadeType.REMOVE)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<SuiteVersion> listSuiteVersion = new ArrayList<SuiteVersion>();
    

    I used fully qualified names to clearly show the Hibernate specific and the standard JPA annotations here.

    The Hibernate specific CascadeType.DELETE_ORPHAN is something else, it is used to tell Hibernate to delete a specific SuiteVersion if you remove it from the collection (without it, the SuiteVersion record would be updated to remove the link to the parent Suite but would remain in the table, being thus an “orphan”).

    Note that if you are using JPA 2.0 (i.e. Hibernate 3.5+), there is now a standard way to deal with orphan records i.e. without using the Hibernate specific annotation. You can specify an orphanRemoval option in your OneToMany (and OneToOne) association. Like this:

    @OneToMany(mappedBy = "suite", cascade = CascadeType.REMOVE, orphanRemoval = true)
    private List<SuiteVersion> listSuiteVersion = new ArrayList<SuiteVersion>();
    

    But this goes beyond this question as this is actually not what you’re looking for.

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

Sidebar

Related Questions

Hii, I have two entities with bidirectional association. Project.java class Project{ int project_id; @OneToMany(mappedBy=project)
I have some problem with this jQuery code. I'm new at this but it
I have some problem with this code, when I click the start button everything
I have some problem with this mongoid. It's my first time to use mongoDB,
I have some problem in my JDBC code. I am trying to connect through
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml
i have some problem to understand array_multisort See how it sorts when two values
i have some problem. when i run this project, only messagebox button ok appear,
I have some problem in matlab since I was new in this programming language.
I have some problem with my JSystem/Java/Eclipse enviromment. I get this error and 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.