P E N C I L
Login
Composite key: Embeddable
class B { 
    @EmbededId    private EmpPk pk; 
    @Embedable     public static class EmpPk {
        private String id1, id2;
    }
}

or

The following support spring data

@IdClass(KeyValue.Id.class)
class Ent {      @Id   String a;   @Id   String b;
}