OneToMany 関係に問題があります。リストを取得しようとしましたが、何も取得されません。論文は私の情報源です:
これがメインです:
public class ModelTest {
public static void main(String[] args) {
//Creating
{
StudyEntity st = new StudyEntity();
st.setPatientName("Edwin");
st.setStudy_pk("111");
new StudyCRUD().create(st);
StudyEntity st2 = new StudyEntity();
st2.setPatientName("Jose");
st2.setStudy_pk("2333");
new StudyCRUD().create(st2); // Persist the object in DB
SeriesEntity se = new SeriesEntity();
se.setSeries_iuid("44444");
se.setStudyentity(st);
new SeriesCRUD().create(se);
SeriesEntity se2 = new SeriesEntity();
se2.setStudyentity(st);
new SeriesCRUD().create(se2); // Persist the object in DB
}
//Retrieving
{
StudyEntity study = new SeriesCRUD().getStudyEntityByID(1); // Get a Object by ID
System.out.println("Name: "+study.getPatientName());
System.out.println("Size: "+study.getStudySeries().size());
}
}
}
結果
名前: エドウィン
サイズ: 0
テーブル情報:
研究実体
ida, DELETED, MODALITY, PATIENTNAME, SENT, STUDY_DATETIME, STUDY_ID, STUDY_PK<br />
1, 0, '', 'Edwin', 0, '', '', '111'<br />
2, 0, '', 'Jose', 0, '', '', '2333'<br />
シリーズ実体
ID, SERIES_IUID, SERIES_PK, ida
1, '', '', 1
2, '', '', 1
エンティティ テーブル:
研究実体
@Entity @Table(name="studyentity")
public class StudyEntity implements Serializable{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="ida")
private long id;
private String patientName;
private String study_id;
private String modality;
@Column(unique=true )
private String study_pk;
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date study_datetime;
private boolean sent;
@Column(columnDefinition="boolean default false")
private boolean deleted;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,mappedBy="studyentity")
private List<SeriesEntity> studySeries;
//getters and setters
シリーズ実体
@Entity @Table(name="seriesentity")
public class SeriesEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ida", nullable = false)
private StudyEntity studyentity;
private String series_pk;
private String series_iuid;
//Getters and Setters