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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:10:53+00:00 2026-06-14T05:10:53+00:00

I am using HIbernate 3.2.5. I have a one-to-many association between Dept and Training

  • 0

I am using HIbernate 3.2.5. I have a one-to-many association between Dept and Training table. One dept is capable of taking more than one training.

<id name="deptId" type="integer" column="DEPT_ID">
      <generator class="assigned"></generator>
  </id>
  <property name="deptName">
      <column name="DEPT_NAME"></column>
  </property>
  <map name="trainingDetails" inverse="false" cascade="delete" lazy="false">
      <key column="DEPT_ID"></key>
      <map-key formula="ID" type="integer"></map-key>
      <one-to-many class="model.Training"/>
  </map>      

When I try to delete an entry:

SessionFactory sf = new Configuration().configure("trial.cfg.xml").buildSessionFactory();
    Session session = sf.openSession();
    Dept department = new Dept();
    department.setDeptId(2);        
    session.delete(department);
    session.flush();
    session.close();

I can see that for the child table an update query is getting printed in the console rather than a delete query:

update training set DEPT_ID=null where DEPT_ID=?

But since the cascade is delete hence the child table should also execute a delete operation rather than an update right?

Please let me know where is my mistake.

Regards,

  • 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-06-14T05:10:54+00:00Added an answer on June 14, 2026 at 5:10 am

    It will do if you use cascade as DELETE_ORPHAN stating that child object can’t exist standalone.

    In addition, you are not loading the object graph before deleting. Perform delete as below:

    SessionFactory sf = new Configuration().configure("trial.cfg.xml")
                                           .buildSessionFactory();
        Session session = sf.openSession();
        //load the object before deleting
        Dept department = session.get(Dept.class, new Integer(2));
        session.delete(department);
        session.flush();
        session.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Hibernate with JPA annotations. I have a one-directional many-to-many association that
I'm trying to make simple many-to-one association, using NHibernate.. I have class Recruit with
I've mapped two entities using JPA (specifically Hibernate). Those entities have a one-to-many relationship
I have a many-to-one association set up like this, in the hbm.xml: <many-to-one name=gigVenue
I want to implement a one-to-many relation using Hibernate (in Java). I have two
i have one problem in one-to-many mapping using hibernate. i have 2 classes, Person
I am using hibernate many to many association. i have 3 tables(STUDENT,COURSE and STUDENT_COURSE).
I am using hibernate. I have one to many relationship. @OneToMany(mappedBy = enrollmentSetupCategory, fetch
I am using Hibernate to do mapping. One of my classes have a set
I'm having some problems using cascade operations on hibernate. I have one entity (TripleDBmodel),

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.