Skip to content

Instantly share code, notes, and snippets.

@rvillablanca
Forked from vltsu/JPA IdClass example
Created January 11, 2017 11:29
Show Gist options
  • Save rvillablanca/8fe506d5a16dbec24f580ac6df877a14 to your computer and use it in GitHub Desktop.
Save rvillablanca/8fe506d5a16dbec24f580ac6df877a14 to your computer and use it in GitHub Desktop.
@Entity
public class Employee {
@Id long empId;
String empName;
...
}
public class DependentId {
String name; // matches name of @Id attribute
long emp; // matches name of @Id attribute and type of Employee PK
}
@Entity
@IdClass(DependentId.class)
public class Dependent {
@Id String name;
// id attribute mapped by join column default
@Id @ManyToOne Employee emp; ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment