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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:15:59+00:00 2026-05-15T22:15:59+00:00

I have a database in which all of the tables have been generated by

  • 0

I have a database in which all of the tables have been generated by Java JPA/Hibernate code. I need to update several tables in my database in a fashion similar to this,

UPDATE Department SET id=100000 WHERE id=0;

Unfortunately this results in the error

ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (departmentuserlink, CONSTRAINT FK96AF44EAB09C41C5 FOREIGN KEY (department_id) REFERENCES department (id))

Here are the Java entities:

@Entity
@Table(name="Department")
public class Department extends AbstractEntity implements IAbstractEntity {

@OneToMany(cascade=CascadeType.ALL, mappedBy="department", fetch=FetchType.EAGER)
private Set<DepartmentJobLink> departmentJobs = new HashSet<DepartmentJobLink>(0);

    //Setters & getters and all that
}



@Entity
@Table(name="edrDepartmentJobLink",     uniqueConstraints={@UniqueConstraint(columnNames={"department_id", "job_id"})})
public class DepartmentJobLink extends AbstractEntity implements IAbstractEntity {

@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="department_id", nullable=false)
private Department department;

    //Setters & getters and all that
}

They both have ID’s in the superclass. So far it looks like everything else about them works great, just running into trouble with updating the primary key of Department. I would appreciate any advice. Thanks.

  • 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-15T22:16:00+00:00Added an answer on May 15, 2026 at 10:16 pm

    Well, what foreign keys does the table being updated have? Sounds like you cannot change the value of department.id because some other table has a foreign key constraint on it’s department_id column pointing to department.id.

    This is actually “A Good Thing” since it means your data is reliable.

    You need to change your update statement so that you are also updating the department_id column of the affected table along with department.id (as well as any other affected tables), or optionally you could ALTER the foreign key constraint so that changes are cascaded. The syntax to do this will vary with your Database implementation.

    This actually doesn’t have anything to do with JPA or Hibernate – it’s purely a result of foreign-key constraints declared in your database (which may have come from a Hibernate mapping and auto-generating the database schema from a Hibernate schema generator tool, but that is irrelevant now).

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

Sidebar

Related Questions

I have a lookup table called metadata_types in my database, which lists all the
We have a database in which all the PKs are GUIDs, and most of
Ok, i have a database in which i have all my users registered with
I have a database class, which manages all my mysql connections for my application.
I have ListView which is saving all data to database. For adding i have
i have a database which contains an arabic tables , i can read it
I have a database which is 6GB in size, with a multitude of tables
We have been asked to get a list of all tables within our SQL
Facts Database: PostgreSQL (latest) Programming language: Java Problem statement (simplified) We have 2 tables
Good day all, I have been learning about databases and database design 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.