Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:48:42+00:00 2026-06-09T13:48:42+00:00

I have problem with my program. I have 2 table with one to many

  • 0

I have problem with my program.
I have 2 table with one to many relation.

In one record in table “A” which be references key in table “B”;

How i can input record in table “B”.
Thanks

Model for table 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;
    }

Model for table 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 + " ]";
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:48:44+00:00Added an answer on June 9, 2026 at 1:48 pm

    You should persist not owner side entity first and then persist owner side entity. According to your codes, you should persist MuatanKtsp entity first. See this example.It may be reference for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: Have made a small mail program which works perfectly on my developer pc
I have a table with 2 rows, one of which represents date and the
I have 2 functions, one that is creating dynamicly a table with input fields,
I have a table which is referenced by foreign keys on many other tables.
This is my server code I have a problem because my program freeze and
I have a problem with 2D transformation program I have the source code import
I have a problem with my iPhone program. I have imported a folder into
Basically i have a problem with this timer program I am trying to put
with my RCP program I have the problem that I want to have more
I have this problem when trying to run hello world program using android SDK.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.