I am quite new to App Engine development and JPA. I am running App
Engine 1.2.6 and I use Eclipse. Here are three problems I've
encountered that perplex me:

1. Servlet receives multiple instances of posts.

I posted 30 distinct records using AJAX. In the Dev environment, my
servlet receives 30 records, but a few of the records appear multiple
times. So several distinct records never made it to my servlet (e.g.,
instead of records 1,2,3,4...30., I may get
4,4,4,4,4,4,7,8,9,10,12,12,12,....29,30) This problem does not occur
when I post these 30 records to the App Engine Production environment.
Firebug confirmed that my javascript program posted 30 different
records. Has anyone encountered this problem? Plus this javascript
program had been tested against a PHP program before and the PHP
program received the correct data.


2. java.lang.IllegalArgumentException:
org.datanucleus.exceptions.NucleusUserException: Columns "Columns
[runWorkout_id, runWorkout_id, runWorkout_id] " have been defined with
3 columns, yet there are only 1 to map to!

3. javax.persistence.PersistenceException: Detected attempt to
establish RunWorkout("18580476422013912411-1263015546674")/
RunGeolocation(1676) as the parent of RunWorkout
("18580476422013912411-1263015546674") but the entity identified by
RunWorkout("18580476422013912411-1263015546674") has already been
persisted without a parent.  A parent cannot be established or changed
once an object has been persisted.

I get 2 and 3 in the Dev Environment every now and then during the
posting of the 30 distinct records. I have 1-many relationship between
two entities. My JPA code to add and update entities have not changed
at all in the last few days. I can't replicate 2 and 3 in the past
hour. But several hours ago, 2 and 3 appeared. Again, I have never
seen these exceptions in the Production environment.  Two days ago, 2
and 3 appeared too, but then disappeared. I don't understand 2 at all
and I am confused as to how 3 could happen.

Here's the snippet of my JPA code:

            EntityManager em = null;
            EntityTransaction tx = null;
            RunWorkout run;
            try {
                em=EMF.get().createEntityManager();
                try {
                        run = em.find(RunWorkout.class,
                                                  
RunWorkout.createKey(user.getUserId(), Long.toString
(startTime)));
                    tx=em.getTransaction();
                                tx.begin();

                                if (run == null) {
                                        em.persist(createRun(user));
                                }
                                else {
                                        if ( distance > run.getDistance()) {
                                                run.setDistance(distance);
                                                run.setDuration(duration);
                                        }
                            run.getRunGeos().add(createGPSStat());
                                }
                                tx.commit();
                }
                ....

Here are my classes:

@Entity
public class RunWorkout implements Workout{
    private static final Logger log = Logger.getLogger
(RunWorkout.class.getName());

    @Id
    @Extension(vendorName = "datanucleus", key="gae.encoded-pk",
value="true")
    private String id;
    private String owner;
    private Date   startTime; // UTC milliseconds
    private int    timeZone;
    private Float  distance;  // meters
    private Long   duration;   // milliseconds
    private String name; // name of Run Workout
    ....
    @OneToMany(cascade=CascadeType.ALL,mappedBy="runWorkout")
    @OrderBy("duration ASC")
    private List<RunGeolocation> runGeos = new
ArrayList<RunGeolocation>();
    ....
}


@Entity
public class RunGeolocation {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key id;

    // Geolocation API data
    private float latitude;
    private float longitude;
    private float accuracy;
    private float altitude;
    private float altitudeAccuracy;
    private float heading;
    private float speed;
    private long  gpsTimestamp;

    // cumulative run statistics at current location
    private long  duration;
    private float distance;

    @ManyToOne(fetch = FetchType.LAZY)
    private RunWorkout runWorkout;
   ....
}

Can someone point out what I did wrong or refer me to documentation
that will give me my DOH! moment once I read (or reread) it?

Thanks,

Art

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to