在JPA持久的地圖,我不知道爲什麼我不能持久的MAP在JPA在GAE如何在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://本地主機:8888/_ah /管理/數據存儲我可以看出那年一直堅持不懈;但是,我永遠無法得到它們;或者,stud.getAnnualReport()總是空的。
EntityManager em;
em = EMF.get().createEntityManager();
AnnualReport thatyear = stud.getAnnualReport().get(yearselected);
我真的不知道該怎麼做。以下是梭哈&年報
梭哈
@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;
我不知道會發生什麼關係。爲什麼我無法獲得那些已經存在的地圖信息?