Posts

Showing posts with the label how to map a composite key with hibernate?

Composite Primary Keys Using Embeddable In Hibernate | Code Factory

Image
Download code and jars :  Link. File : UserId.java package com.codeFactory.bean; import java.io.Serializable; import javax.persistence.Embeddable; @Embeddable public class UserId implements Serializable {  String firstName;  String lastName;  public String getFirstName() {   return firstName;  }  public void setFirstName(String firstName) {   this.firstName = firstName;  }  public String getLastName() {   return lastName;  }  public void setLastName(String lastName) {   this.lastName = lastName;  } } File : User.java package com.codeFactory.bean; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; @Entity public class User {  @EmbeddedId  @AttributeOverride(name = "firstName", column = @Column(name = "fid_firstnam...

Composite Primary Keys In Hibernate | Code Factory

Image
Download code and jars :  Link. File : ProjectId.java package com.codeFactory.bean; import java.io.Serializable; public class ProjectId implements Serializable{ int departmentId; int projectId; public int getDepartmentId() { return departmentId; } public void setDepartmentId(int departmentId) { this.departmentId = departmentId; } public int getProjectId() { return projectId; } public void setProjectId(int projectId) { this.projectId = projectId; } } File : Project.java package com.codeFactory.bean; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; @Entity @IdClass(ProjectId.class) public class Project { @Id int departmentId; @Id int projectId; public int getDepartmentId() { return departmentId; } public void setDepartmentId(int departmentId) { this.departmentId = departmentId; } public int getProjectId() { return...