MountainClimb / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

Children objects are deleted from the datastore but still appear in the Data Viewer #140

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Children objects of a one-to-one unidirectional relationship are deleted
from the datastore when its parent is deleted but they still show in the
Data Viewer.

The getObjectById() methods throw correctly the JDOObjectNotFoundException
but the DayCallsStat object still appear in the Data Viewer.

Here's the snippet reproducing the problem:
----------------
        PersistenceManager pm = PMF.get().getPersistenceManager();

        String userId = "0";
        Key userKey = KeyFactory.createKey(User.class.getSimpleName(), userId);
        String userEncodedKey = KeyFactory.keyToString(userKey);
        String dayCallsStatEncodedKey = KeyFactory.createKeyString(userKey,
DayCallsStat.class.getSimpleName(), userId);
        User user = null;
        Transaction tx = pm.currentTransaction();
        try {
            for(int tries=0; tries < 4; tries++) {
                tx.begin();
                try {
                    try {
                        user = pm.getObjectById(User.class, userEncodedKey);
                        tx.commit();
                        break;
                    } catch(JDOObjectNotFoundException e) {
                        user = new User();
                        user.setUserId(userId);
                        user.setEncodedKey(userEncodedKey);

                        long now = System.currentTimeMillis();
                        DayCallsStat dayCallsStat = new DayCallsStat();

dayCallsStat.setStartOfPeriodCallsTimestamp(Utils.getStartOfDayTimestamp(now));

dayCallsStat.setEndOfPeriodCallsTimestamp(Utils.getEndOfDayTimestamp(now));
                        dayCallsStat.setUserId(userId);
                        dayCallsStat.setEncodedKey(dayCallsStatEncodedKey);
                        user.setDayCallsStat(dayCallsStat);
                        pm.makePersistent(user);
                        tx.commit();
                        logger.info("User created. User: " + userId);
                        break;
                    }
                } catch (JDOException r) {
                    if(!(r instanceof JDOCanRetryException)) {
                        boolean isConcMod = false;
                        Throwable cause = r;
                        while(cause.getCause() != null) {
                            cause = cause.getCause();
                            if(cause instanceof
ConcurrentModificationException) {
                                isConcMod = true;
                                break;
                            }
                        }
                        if(!isConcMod) {
                            throw r;                           
                        }
                    }
                    if(tries == 3 ) {
                        throw r;
                    }
                }
            }
        } finally {
            if(tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }

        pm = PMF.get().getPersistenceManager();
        tx = pm.currentTransaction();
        try {
            for(int i=0; i< 4; i++) {
                tx.begin();
                try {
                    try {
                        user = pm.getObjectById(User.class, userKey);
                        pm.deletePersistent(user);
                        tx.commit();
                        logger.info("Deleted User. User: " + userId);
                        break;
                    } catch(JDOObjectNotFoundException e) {
                        logger.warning("User not found. User: " + userId);
                        break;
                    }
                } catch (JDOException r) {
                    if(!(r instanceof JDOCanRetryException)) {
                        boolean isConcMod = false;
                        Throwable cause = r;
                        while(cause.getCause() != null) {
                            cause = cause.getCause();
                            if(cause instanceof
ConcurrentModificationException) {
                                isConcMod = true;
                                break;
                            }
                        }
                        if(!isConcMod) {
                            throw r;                           
                        }
                    }
                    if(i == 3 ) {
                        throw r;
                    }
                }
            }
        } finally {
            if(tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }

        pm = PMF.get().getPersistenceManager();
        try {
            pm.getObjectById(userEncodedKey);
            throw new ServletException("User should not exist.");
        } catch (JDOObjectNotFoundException e) {
            logger.info("User was already deleted.");
        }

        try {
            pm.getObjectById(dayCallsStatEncodedKey);
            throw new ServletException("DayCallsStat should not exist.");
        } catch (JDOObjectNotFoundException e) {
            logger.info("DayCallsStat was already deleted.");
        }
------------

Original issue reported on code.google.com by eris4.mu...@gmail.com on 6 Oct 2009 at 7:16

GoogleCodeExporter commented 8 years ago
sadly the "snippet" doesnt define the classes involved, so not reproduceable 
and downgraded to low priority. Obviously looking at the log would tell you more

Original comment by googleco...@yahoo.co.uk on 29 Sep 2011 at 1:15

GoogleCodeExporter commented 8 years ago
Marking as invalid since not enough information to reproduce was provided. Feel 
free to reopen if you can provide additional info.

Original comment by max.r...@gmail.com on 20 Jan 2012 at 8:50