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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:34:32+00:00 2026-06-15T08:34:32+00:00

If you have a IdClass like public class EmployeePK implements Serializable { private String

  • 0

If you have a IdClass like

public class EmployeePK implements Serializable {

 private String empName;
 private Date birthDay;

 public EmployeePK() {
 }

 public String getName() {
     return this.empName;
 }

 public void setName(String name) {
     this.empName = name;
 }

 public Date getBirthDay() {
     return this.birthDay;
 }

 public void setBirthDay(Date date) {
     this.birthDay = date;
 }

 public int hashCode() {
     return (int)this.empName.hashCode();
 }

 public boolean equals(Object obj) {
     if (obj == this) return true;
     if (!(obj instanceof EmployeePK)) return false;
     EmployeePK pk = (EmployeePK) obj;
     return pk.birthDay.equals(this.birthDay) && pk.empName.equals(this.empName);
 }

}

and

@IdClass(EmployeePK.class)
@Entity
public class Employee implements Serializable{

   @Id String empName;
   @Id Date birthDay;
   ...

    public Employee (String empName, Date birthDay){
    this.empName= empName;
    this.birthDay= birthDay;
}
...
}

how do you make an update query?

    EntityManagerFactory emf = Persistence
            .createEntityManagerFactory("JPA_Compositekey");
    EntityManager em = emf.createEntityManager();
    try {
        em.getTransaction().begin();
        Employee anemployee = em.find( **WHAT DO YOU FILL HERE **)
...

Or must I use a object from the PK class and what to do if you have a just a person that you need to update.

Thx all

  • 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-15T08:34:33+00:00Added an answer on June 15, 2026 at 8:34 am

    As for every other entity: you give an instance of the ID:

    EmployeePK pk = new EmployeePK(...);
    Employee anemployee = em.find(Employee.class, pk);
    

    And to update the employee, then just as with any other entity: you modify its fields, and the new state is automatically persisted when the transaction commits. Just make sure not to update the name and the birth date: as they’re part of the PK, they are immutable. That’s one of the many good reasons not to use composite keys, especially functional composite keys.

    Everything would be much easier with an autogenerated surrogate key.

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

Sidebar

Related Questions

I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
I would like to have a class that handles population of lists of data
I have 3 primary keys like in the following example: @Entity class User {
I have a problem cloning dynamic object with the code like this: public void
Suppose I have a one-to-many relationship like this: class Book(Base): __tablename__ = books id
i have a t_my_class table structure like below (MySql table) id class group age
I have a table like: ------------------- id class name sub ------------------------ 1 mca aditya
I have data in database like this id class gender 1 A F 2
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=

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.