I use spring boot 2, jpa and hibernate
with this code
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Samplings {
@Id
@GenericGenerator(name = "samplings_id_seq", strategy="com.lcm.model.SamplingSequenceGenerator")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "samplings_id_seq")
private Integer id;
@OneToMany(mappedBy = "sampling")
private List<Samples> samples = new ArrayList<>();
}
@Entity
@IdClass(SamplesPK.class)
public class Samples {
@Id
private String sampleLetter;
@Id
@ManyToOne(optional = false)
@JoinColumns({
@JoinColumn(name = "id", referencedColumnName = "id")})
private Samplings sampling;
}
public class SamplesPK implements Serializable {
private Integer id;
private String sampleLetter;
public SamplesPK(Integer id, String sampleLetter) {
this.id = id;
this.sampleLetter = sampleLetter;
}
.... //get / set
}
I get this error:
org.hibernate.AnnotationException: Property of @IdClass not found in entity com.lcm.model.Samples:: id
The names of the fields or properties in the primary key class and the primary key fields or properties of the entity must correspond and their types must be the same. From docs here.
Your Samples
class should have its id as the same type of your SamplesPK
.
You should have a @Id private Integer id
in your Samples
class
It looks like you miss some components of your SamplesPk.class in your Samples entity.
It is called Samples:: samplingId
Here you have an example LINK
EDIT:
So your entity should look like this :
@Entity
@IdClass(SamplesPK.class)
public class Samples {
@Id
private String sampleLetter;
@Id
private Integer id;
@Id
@ManyToOne(optional = false)
@JoinColumns({
@JoinColumn(name = "sampling_id", referencedColumnName = "id")})
private Samplings sampling;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With