我不知道为什么我不能在 GAE 中的 JPA 中持久化 MAP
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;
我不知道会发生什么。为什么我无法获取那些已经持久化的地图信息?