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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:04:10+00:00 2026-05-21T09:04:10+00:00

I am using hibernate 3 and attempting to delete a record in the database,

  • 0

I am using hibernate 3 and attempting to delete a record in the database, and the delete is not working as I would expect. The schema hibernate is working against (in pseudocode):

create table Employer(
    employer_id number(12) primary key,
    employer_name varchar2(50)
);

create table Employee(
    employee_id number(12) primary key,
    employee_name varchar2(50),
    employer_id number(12) foreign key references employer.employer_id not null
);

create table Employee_Roles(
    role_id number(12) primary key,
    employee_id number(12) foreign key references employee.employee_id not null,
    role varchar2(50)
);

My hibernate class mappings look something like:

@Entity
public class Employer{

    @Id
    @Column(name = "EMPLOYER_ID")
    private long id;

    @Column
    private String name;


    @OneToMany(targetEntity = Employee.class, fetch = FetchType.EAGER)
    @JoinColumn(name = "employer_id")
    @Cascade(CascadeType.ALL)
    private Set<Employee> employees;
}

@Entity
public class Employee{

    @ManyToOne(targetEntity = Employer.class)
    @JoinColumn(name = "employer_id")
    @Cascade(value = CascadeType.SAVE_UPDATE)
    private Employer employer;

    @OneToMany(targetEntity = EmployeeRole.class, fetch = FetchType.EAGER)
    @JoinColumn(name = "employee_id")
    @Cascade(CascadeType.ALL)
    private Set<Employee> employees;
}

@Entity
public class EmployeeRole{

    @ManyToOne(targetEntity = Employee.class)
    @JoinColumn(name = "employee_id")
    @Cascade(value = CascadeType.SAVE_UPDATE)
    private Employee employee;
}

Now with this configuration I am calling:

getCurrentSession().delete(someEmployerEntity);

What is occurring is:

Hibernate: update EMPLOYEE set EMPLOYEE_ID=null where EMPLOYEE_ID=?
Hibernate: update EMPLOYEE_ROLE set employee_id=null where employee_id==?
[2011-04-15 15:59:53,487] JDBCExceptionReporter WARN  - SQL Error: -10, SQLState: 23502
[2011-04-15 15:59:53,487] JDBCExceptionReporter ERROR - integrity constraint violation: NOT NULL check constraint; SYS_CT_10058 table: EMPLOYEE_ROLE

and an exception being raised. What I am expecting as a result of the session.remove(..) call is the employer record to be deleted, as well as all employee records associated with the employer and all EmployeeRole records associated with the deleted employee records. Is this a correct assumption? Or am I misunderstanding a key concept here?

  • 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-21T09:04:11+00:00Added an answer on May 21, 2026 at 9:04 am

    Cascade all-delete-orphan should solve your problem. However, it is part of Hibernate and not EJB standard. If you want to do it and do not be trapped in your vendors’ solution, I would suggest you to have a look to this article.

    Good luck!

    EDIT: following your suggestions I added the ‘mappedBy’ attributes to the @OneToMany annotations which seems to be the annotations way of using inverse=”true” for specifying the owning relationships. The relevant changed sections of the relationships look like:

    public class Employee{
    
        @OneToMany(targetEntity = EmployeeRole.class, mappedBy="employee", fetch = FetchType.EAGER,  cascadeType=CascadeType.ALL)
        private Set<EmployeeRole> employeeRoles;
    }
    
    
    public class Employer{
    
        @OneToMany(targetEntity = Employee.class, mappedBy="employer", fetch = FetchType.EAGER, cascadeType=CascadeType.ALL)
        private Set<Employee> employees;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Hibernate for ORM of my Java app to an Oracle database (not
When using Hibernate 2nd level cache and query cache and not specifying anything inside
I am using Hibernate in a Java application to access my Database and it
So I'm using hibernate and working with an application that manages time. What is
I am using hibernate. i have read some where about Example.create. what is it
I'm using Hibernate 3.2.6 and I'm attempting to make a query like so: select
I'm using Hibernate 3.5.6 as my JPA 2.0 implementation. I'm attempting to build an
I am attempting to do unit testing of my DAO (using Spring and Hibernate).
I am using Hibernate 4 and would like to simply list all rows of
I am using the create-drop option for development, when deploying to mysql database (using

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.