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

  • Home
  • SEARCH
  • 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 4327526
In Process

The Archive Base Latest Questions

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

If I have this 3 entities : @Entity public class Student { @Id @GeneratedValue(strategy=GenerationType.IDENTITY)

  • 0

If I have this 3 entities :

@Entity
public class Student {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected Long id;

private String name; 

}

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Course {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected Long id;

@OneToMany
private List<Student> students;

private String name; 

}

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Group {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected Long id;

@OneToMany
private List<Student> students;

private String name; 

}

How can I delete students with a JPQL query ?

I try

DELETE FROM Student s
WHERE s.name = “John Doe”

But I have

Cannot delete or update a parent row: a foreign key constraint fails (database, CONSTRAINT FK_course_student_students_ID FOREIGN KEY (students_ID) REFERENCES student (ID))

I need to do this in pure JPQL for performance, I can’t do an entity.remove, because I have 10000 John doe and I need to delete them in a second.

Why JPQL doesn’t say : “Hey, let’s remove this john doe from this biology course, he doesn’t exist” instead of “Hey, the biology course is so important that no student can be remove from this course ! “

What I am missing and what sort of annotation I have to use ?

Thanks !

Edit : Add a @JoinColumn to the OnToMany relationship could work, unless the students are referenced by different tables…

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

    By default unidirectional one-to-many relationship is mapped via join table. If you don’t have any special requirements about using join talbe you can use foreign key in Student instead, it can be configured as follows:

    @OneToMany 
    @JoinColumn
    private List<Student> students; 
    

    It also should solve your problem with constrain violation.

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

Sidebar

Related Questions

I have the following entities: @Entity public class Alert implements Serializable { private long
I have two JPA entities: @Entity public class TaskSchedule { ... private String name;
I have problems creating a custom query. This is what entities: @Entity public class
I have this class public class Address:Entity { public virtual string Address1 { get;
If I have entities like: @Entity public class Person { public String name; @OneToMany
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have the following (simplified) Hibernate entities: @Entity @Table(name = package) public class Package
We have the following two entities with many-to-many association: @Entity public class Role {
Assume there are two entities with ManyToOne relation: @Entity public class A { private
i have the following classes: //Product class public class Product { @Id @GeneratedValue private

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.