Google app engine 如何在GAE中持久化JPA映射
我不知道为什么我不能在GAE中持久映射JPAGoogle app engine 如何在GAE中持久化JPA映射,google-app-engine,jpa,map,persistent,Google App Engine,Jpa,Map,Persistent,我不知道为什么我不能在GAE中持久映射JPA AnnualReport thatyear = ....... if (stud.getAnnualReport() == null){ Map<Integer,AnnualReport> temp = new HashMap<Integer,AnnualReport>(); temp.put(thatyear.getAttrKey(), thatyear);
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();
}
}
我真的不知道该怎么办。以下是螺柱和年度报告之间的关系
@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;
螺柱
我不知道会发生什么。为什么我不能获得那些已经持久的地图信息 不知道为什么没有得到预期的结果,但是没有提供调试信息。您可以使用日志轻松地跟踪持久化过程,告诉您实际持久化到GAE实体对象中的内容。GAE在以下位置有一个(JDO)单元测试: 这表明了正确的行为(而且由于JDO/JPA只是持久性引擎上的一个包装器,没有理由认为使用JPA不会很好地持久化) 编辑:事实上,我刚刚在添加了一个JPA地图测试,效果很好
@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;