Try with ManyToOne and change locationId to location :
@Entity
class Location {
@Id
@NotNull
private Long id;
}
class AId implements Serializable {
private Long location;
private String userName;
}
@Entity
@IdClass(AId.class)
class A {
@Id
private String userName
@Id
@NotNull
@ManyToOne
@JoinColumn(name = "location_id", nullable=false, foreignKey = @ForeignKey(name = ...))
private Location location;
}