Saya tidak tahu mengapa saya tidak bisa mempertahankan MAP di JPA di GAE
AnnualReport thatyear = .......
if (stud.getAnnualReport() == null){
Map<Integer,AnnualReport> temp = new HashMap<Integer,AnnualReport>();
temp.put(thatyear.getAttrKey(), thatyear);
stud.setAnnualReport(temp);
} else{
Map<Integer,AnnualReport> temp2 = stud.getAnnualReport();
temp2.put(thatyear.getAttrKey(), thatyear);
stud.setAnnualReport(temp2);
}
em.getTransaction().begin();
try {
em.persist(stud);
em.getTransaction().commit();
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
}
Sebenarnya di http:// localhost :8888/_ah/admin/datastore saya dapat melihat tahun itu terus berlanjut; Namun, saya tidak pernah bisa mendapatkannya; atau, stud.getAnnualReport() selalu kosong.
EntityManager em;
em = EMF.get().createEntityManager();
AnnualReport thatyear = stud.getAnnualReport().get(yearselected);
Saya benar-benar tidak tahu harus berbuat apa. Berikut hubungan antara Stud & AnnualReport
Pejantan
@Entity( name = "Stud")
public class Stud{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key studID;
private String lastName = new String();
private Map<Integer,AnnualReport>annualReport = new HashMap<Integer,AnnualReport>(20);
@OneToMany(mappedBy="stud",cascade = CascadeType.ALL)
@MapKey(name = "attrKey")
@Basic
public Map<Integer, AnnualReport> getAnnualReport() {
return annualReport;
}
Laporan Tahunan
@Entity( name = "AnnualReport")
public class AnnualReport implements Serializable{
private static final long serialVersionUID = 3581307841164176872L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key annualReportID;
public int attrKey;
@ManyToOne
Stud stud;
private String attendSchoolNote;
Saya tidak tahu apa yang terjadi. Mengapa saya tidak bisa mendapatkan informasi peta yang sudah ada?