I suspect the problem is that you are using a specific HashSetinstead of an interface Set. Try this (if it has Idsomewhere):
@Entity
public class Schedule implements java.io.Serializable {
private String scheduleName;
private Set<Step> steps = new HashSet<Step>();
@OneToMany(mappedBy="schedule", cascade=CascadeType.ALL, fetch=FetchType.EAGER)
public Set<Step> getSteps() {
return steps;
}
}
, . :
...
, HashSet. () . , persist(), , Hibernate HashSet Hibernate Set.
, :
@Id (, , ).Step equals/hashCode (. ).
: ( PostgreSQL, , , ). :
@Entity
public class Step implements java.io.Serializable {
private Long id;
private String duration;
private String stepType;
private Schedule schedule;
@ManyToOne(fetch = FetchType.LAZY)
public Schedule getSchedule() { return schedule; }
@Id @GeneratedValue
public Long getId() { return id; }
}
@Entity
public class Schedule implements java.io.Serializable {
private Long id;
private String scheduleName;
private Set<Step> steps = new HashSet<Step>();
@OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
public Set<Step> getSteps() { return steps; }
@Id @GeneratedValue
public Long getId() { return id; }
}
DDL:
create table Schedule (
id bigint generated by default as identity (start with 1),
scheduleName varchar(255),
primary key (id)
)
create table Step (
id bigint generated by default as identity (start with 1),
duration varchar(255),
stepType varchar(255),
schedule_id bigint,
primary key (id)
)
alter table Step
add constraint FK277AEC7B775928
foreign key (schedule_id)
references Schedule
, HashSet OneToMany, Hibernate ( , ), :
Caused by: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.stackoverflow.q4083744.Schedule.steps