Я не знаю, почему я не могу сохранить MAP в JPA в 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();
}
}
На самом деле в http://localhost:8888/_ah/admin/datastore я вижу, что тот год был постоянным; Однако я никогда не смогу их получить; или stud.getAnnualReport() всегда пуст.
EntityManager em;
em = EMF.get().createEntityManager();
AnnualReport thatyear = stud.getAnnualReport().get(yearselected);
Я действительно не знаю, что делать. Ниже приводится взаимосвязь между Stud и AnnualReport.
Стад
@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;
}
Годовой отчет
@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;
Я не знаю, что происходит. Почему я не могу получить ту информацию о карте, которая уже является постоянной?