Q:

Composite Primary Key embedded in attribute JPA

I am trying to declare a composite primary key using the @Idclass annotation.
The primary key for my class is composed of 3 parts, 2 of which are attributes of the class itself, but one of them is 'embedded' in another attribute:
@IdClass(value = DivisionPK.class)
public class Division {

private String season;
@Id
private String level;
@Id
private String group;

Inside the DivisonPK class, I have declared all the attributes (seasonId, group, and level). How do I, inside the division class, say that season.getId() is the 3rd part of the primary key?

A:

You need to specify Season as a key class:
@IdClass(value = DivisionPK.class)
public class Division {

   @EmbeddedId
   private Season season;

   @Id
   private String level;

   @Id
   private String group;
}

@Embeddable
public class Season implements Serializable {
  // you fields and code here
}

