Last active
October 12, 2017 16:50
-
-
Save rastadrian/6db1adb18ad1ab4099ba947a3e599921 to your computer and use it in GitHub Desktop.
JPA Composite Key Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Getter | |
@Setter | |
@Entity | |
@IdClass(MyEntity.CompositeKey.class) | |
@Table(name = "ENTITY_TABLE") | |
public class MyEntity implements Serializable { | |
@Id | |
@Column(name = "FIRST_ID", nullable = false) | |
private String firstId; | |
@Id | |
@Column(name = "SECOND_ID", nullable = false) | |
private String secondId; | |
@Id | |
@Column(name = "THIRD_ID", nullable = false) | |
private String thirdId; | |
@Column(name = "STRING_FIELD") | |
private String stringField; | |
@Column(name = "INT_FIELD") | |
private Integer intField; | |
@Getter | |
@Setter | |
public static class CompositeKey implements Serializable { | |
String firstId; | |
String secondId; | |
String thirdId; | |
} | |
} | |
@Repository | |
public interface MyEntityRepository extends CrudRepository<MyEntity, MyEntity.CompositeKey> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment