Search code examples
javahibernatespring-bootannotationshibernate-mapping

I'm getting error in @OneToMany hibernate mapping?


I'm trying to have one to many connection between two classes but im getting this error org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany.

here is my code,

Job.java

@OneToMany
@JoinColumn(name = "id", referencedColumnName = "id", insertable = false, updatable = false)

private Set<JobCostSplit> jobCostSplit;

JobCostSplit.java

@Column(name = "job_id")
private Long jobId;

@JsonIgnore
@OneToMany
@JoinColumn(name = "job_id", referencedColumnName = "id", insertable = false, updatable = false)
private Job job;

Solution

  • You annotate your Job with @OneToMany. Means you will have one attribute on Job and more on JobCostSplit.

    So if you want to have one Job and more JobCostSplit you have to set it like this:

    @ManyToOne
    @JoinColumn(name = "job_id", referencedColumnName = "id", insertable = false, updatable = false)
    private Job job;