วิธีทำแผนที่แบบถาวรใน JPA ใน GAE

ฉันไม่รู้ว่าทำไมฉันไม่สามารถคง 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);

ฉันไม่รู้จริงๆว่าต้องทำอย่างไร ต่อไปนี้เป็นความสัมพันธ์ระหว่างสตั๊ดและรายงานประจำปี

สตั๊ด

@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;

ฉันไม่รู้ว่าเกิดอะไรขึ้น เหตุใดฉันจึงไม่สามารถรับข้อมูลแผนที่ที่มีอยู่แล้วได้


person user1654099    schedule 24.10.2012    source แหล่งที่มา


คำตอบ (1)


ไม่รู้ว่าทำไมคุณไม่ได้รับผลลัพธ์ที่คาดหวัง แต่จากนั้นคุณก็ไม่มีข้อมูลการแก้ไขข้อบกพร่อง คุณสามารถติดตามกระบวนการคงอยู่ได้อย่างง่ายดายโดยใช้บันทึก โดยบอกคุณว่าจริงๆ แล้วมีอะไรคงอยู่ในออบเจ็กต์เอนทิตี GAE GAE มีการทดสอบหน่วย (JDO) ที่ http://code.google.com/p/datanucleus-appengine/source/browse/trunk/tests/com/google/appengine/datanucleus/jdo/JDOMapTestjava

ซึ่งแสดงให้เห็นถึงพฤติกรรมที่ถูกต้อง (และเนื่องจาก JDO/JPA เป็นเพียงสิ่งห่อหุ้มเหนือกลไกการคงอยู่ จึงไม่มีเหตุผลที่จะคิดว่าสิ่งเดียวกันจะไม่คงอยู่ได้ดีเมื่อใช้ JPA)

แก้ไข : อันที่จริงฉันเพิ่งเพิ่มการทดสอบสำหรับแผนที่ JPA ที่ http://code.google.com/p/datanucleus-appengine/source/browse/trunk/tests/com/google/appengine/datanucleus/jpa/JPAMapTest.java และทำงานได้ดี

person DataNucleus    schedule 24.10.2012