プログラムに問題があります。1対多の関係を持つ2つのテーブルがあります。
テーブル「A」の1つのレコードで、テーブル「B」のキーを参照します。
テーブル「B」にレコードを入力する方法。ありがとう
テーブルAのモデル
@Entity
@Table(name = "muatan_ktsp", catalog = "bansm", schema = "public")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "MuatanKtsp.findAll", query = "SELECT m FROM MuatanKtsp m"),
@NamedQuery(name = "MuatanKtsp.findByMuatanKtspDate", query = "SELECT m FROM MuatanKtsp m WHERE m.muatanKtspDate = :muatanKtspDate"),
@NamedQuery(name = "MuatanKtsp.findByMuatanKtspTime", query = "SELECT m FROM MuatanKtsp m WHERE m.muatanKtspTime = :muatanKtspTime"),
@NamedQuery(name = "MuatanKtsp.findByOrderDateDESC", query = "SELECT m FROM MuatanKtsp m ORDER BY m.muatanKtspDate DESC")})
public class MuatanKtsp implements Serializable {
@Column(name = "muatan_ktsp_date",insertable = false)
@Temporal(TemporalType.DATE)
private Date muatanKtspDate;
@Column(name = "muatan_ktsp_time",insertable = false)
@Temporal(TemporalType.TIME)
private Date muatanKtspTime;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "muatanKtspId")
private List<Penjurusan> penjurusanCollection;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "muatanKtspId")
private List<PengaturanBebanBelajar> pengaturanBebanBelajarCollection;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "muatanKtspId")
private List<PendidikanKecakapanHidup> pendidikanKecakapanHidupCollection;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "muatanKtspId")
private List<PendidikanGlobalLokal> pendidikanGlobalLokalCollection;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "muatanKtspId")
private List<MuatanLokal> muatanLokalCollection;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "muatanKtspId")
private List<MataPelajaran> mataPelajaranCollection;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "muatanKtspId")
private List<KriteriaKenaikanKelas> kriteriaKenaikanKelasCollection;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "muatanKtspId")
private List<KriteriaKelulusan> kriteriaKelulusanCollection;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "muatanKtspId")
private List<KegiatanPengembanganDiri> kegiatanPengembanganDiriCollection;
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "muatan_ktsp_id", unique = true)
private String muatanKtspId;
public MuatanKtsp() {
}
public MuatanKtsp(String muatanKtspId) {
this.muatanKtspId = muatanKtspId;
}
public Object getMuatanKtspId() {
return muatanKtspId;
}
public void setMuatanKtspId(String muatanKtspId) {
this.muatanKtspId = muatanKtspId;
}
public Date getMuatanKtspDate() {
return muatanKtspDate;
}
public void setMuatanKtspDate(Date muatanKtspDate) {
this.muatanKtspDate = muatanKtspDate;
}
public Date getMuatanKtspTime() {
return muatanKtspTime;
}
public void setMuatanKtspTime(Date muatanKtspTime) {
this.muatanKtspTime = muatanKtspTime;
}
@Override
public int hashCode() {
int hash = 0;
hash += (muatanKtspId != null ? muatanKtspId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof MuatanKtsp)) {
return false;
}
MuatanKtsp other = (MuatanKtsp) object;
if ((this.muatanKtspId == null && other.muatanKtspId != null) || (this.muatanKtspId != null && !this.muatanKtspId.equals(other.muatanKtspId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "bansm.model.MuatanKtsp[ muatanKtspId=" + muatanKtspId + " ]";
}
@XmlTransient
public List<KegiatanPengembanganDiri> getKegiatanPengembanganDiriCollection() {
return kegiatanPengembanganDiriCollection;
}
public void setKegiatanPengembanganDiriCollection(List<KegiatanPengembanganDiri> kegiatanPengembanganDiriCollection) {
this.kegiatanPengembanganDiriCollection = kegiatanPengembanganDiriCollection;
}
@XmlTransient
public List<KriteriaKelulusan> getKriteriaKelulusanCollection() {
return kriteriaKelulusanCollection;
}
public void setKriteriaKelulusanCollection(List<KriteriaKelulusan> kriteriaKelulusanCollection) {
this.kriteriaKelulusanCollection = kriteriaKelulusanCollection;
}
@XmlTransient
public List<KriteriaKenaikanKelas> getKriteriaKenaikanKelasCollection() {
return kriteriaKenaikanKelasCollection;
}
public void setKriteriaKenaikanKelasCollection(List<KriteriaKenaikanKelas> kriteriaKenaikanKelasCollection) {
this.kriteriaKenaikanKelasCollection = kriteriaKenaikanKelasCollection;
}
@XmlTransient
public List<MataPelajaran> getMataPelajaranCollection() {
return mataPelajaranCollection;
}
public void setMataPelajaranCollection(List<MataPelajaran> mataPelajaranCollection) {
this.mataPelajaranCollection = mataPelajaranCollection;
}
@XmlTransient
public List<MuatanLokal> getMuatanLokalCollection() {
return muatanLokalCollection;
}
public void setMuatanLokalCollection(List<MuatanLokal> muatanLokalCollection) {
this.muatanLokalCollection = muatanLokalCollection;
}
@XmlTransient
public List<PendidikanGlobalLokal> getPendidikanGlobalLokalCollection() {
return pendidikanGlobalLokalCollection;
}
public void setPendidikanGlobalLokalCollection(List<PendidikanGlobalLokal> pendidikanGlobalLokalCollection) {
this.pendidikanGlobalLokalCollection = pendidikanGlobalLokalCollection;
}
@XmlTransient
public List<PendidikanKecakapanHidup> getPendidikanKecakapanHidupCollection() {
return pendidikanKecakapanHidupCollection;
}
public void setPendidikanKecakapanHidupCollection(List<PendidikanKecakapanHidup> pendidikanKecakapanHidupCollection) {
this.pendidikanKecakapanHidupCollection = pendidikanKecakapanHidupCollection;
}
@XmlTransient
public List<PengaturanBebanBelajar> getPengaturanBebanBelajarCollection() {
return pengaturanBebanBelajarCollection;
}
public void setPengaturanBebanBelajarCollection(List<PengaturanBebanBelajar> pengaturanBebanBelajarCollection) {
this.pengaturanBebanBelajarCollection = pengaturanBebanBelajarCollection;
}
@XmlTransient
public List<Penjurusan> getPenjurusanCollection() {
return penjurusanCollection;
}
public void setPenjurusanCollection(List<Penjurusan> penjurusanCollection) {
this.penjurusanCollection = penjurusanCollection;
}
テーブル B のモデル
@Entity
@Table(name = "mata_pelajaran", catalog = "bansm", schema = "public")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "MataPelajaran.findAll", query = "SELECT m FROM MataPelajaran m"),
@NamedQuery(name = "MataPelajaran.findByMataPelajaran", query = "SELECT m FROM MataPelajaran m WHERE m.mataPelajaran = :mataPelajaran"),
@NamedQuery(name = "MataPelajaran.findByKkm", query = "SELECT m FROM MataPelajaran m WHERE m.kkm = :kkm"),
@NamedQuery(name = "MataPelajaran.findByMataPelajaranId", query = "SELECT m FROM MataPelajaran m WHERE m.mataPelajaranId = :mataPelajaranId")})
public class MataPelajaran implements Serializable {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
@Column(name = "mata_pelajaran")
private String mataPelajaran;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "kkm", precision = 17, scale = 17)
private Double kkm;
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(name = "mata_pelajaran_id", unique=true)
private String mataPelajaranId;
@JoinColumn(name = "muatan_ktsp_id", referencedColumnName = "muatan_ktsp_id")
@ManyToOne
private MuatanKtsp muatanKtspId;
public MataPelajaran() {
}
public MataPelajaran(String mataPelajaranId) {
this.mataPelajaranId = mataPelajaranId;
}
public MataPelajaran(String mataPelajaranId, String mataPelajaran) {
this.mataPelajaranId = mataPelajaranId;
this.mataPelajaran = mataPelajaran;
}
public String getMataPelajaran() {
return mataPelajaran;
}
public void setMataPelajaran(String mataPelajaran) {
this.mataPelajaran = mataPelajaran;
}
public Double getKkm() {
return kkm;
}
public void setKkm(Double kkm) {
this.kkm = kkm;
}
public String getMataPelajaranId() {
return mataPelajaranId;
}
public void setMataPelajaranId(String mataPelajaranId) {
this.mataPelajaranId = mataPelajaranId;
}
public MuatanKtsp getMuatanKtspId() {
return muatanKtspId;
}
public void setMuatanKtspId(MuatanKtsp muatanKtspId) {
this.muatanKtspId = muatanKtspId;
}
@Override
public int hashCode() {
int hash = 0;
hash += (mataPelajaranId != null ? mataPelajaranId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof MataPelajaran)) {
return false;
}
MataPelajaran other = (MataPelajaran) object;
if ((this.mataPelajaranId == null && other.mataPelajaranId != null) || (this.mataPelajaranId != null && !this.mataPelajaranId.equals(other.mataPelajaranId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "bansm.model.MataPelajaran[ mataPelajaranId=" + mataPelajaranId + " ]";
}
}