thanks so much for checking into this Max.

The data that I'm saving is user generated, so there's not a set
script for it.  Conceptually what I'm doing is this:

                Bundle bundle = new Bundle();
                
                bundle.setName("My Bundle");
                bundle.setDescription(new
com.google.appengine.api.datastore.Text("My Description"));
                bundle.setPricingModel(PricingModel.PER_GUEST);
                
                RatePlan ratePlan = new RatePlan();
                ratePlan.setPricingModel(PricingModel.PER_GUEST);
                ratePlan.setAdultPrice(new java.math.BigDecimal("300.00"));
                ratePlan.setYouthPrice(new java.math.BigDecimal("275.00"));
                
                bundle.setRatePlan(ratePlan);
                
                List<Key> activityIds = getActivityIds();
                int i = 0;
                for (Key id : activityIds) {
                        BundledActivity bundledActivity = new BundledActivity();
                        bundledActivity.setDay(++i);
                        
                        ActivityFK activityFk = new ActivityFK();
                        activityFk.setKey(id);
                        activityFk.setName("activity " + i);
                        activityFk.setPricingModel(PricingModel.PER_GUEST);
                        
                        bundledActivity.setActivity(activityFk);
                        
                        RatePlan activityRate = new RatePlan();
                        activityRate.setPricingModel(PricingModel.PER_GUEST);
                        activityRate.setAdultPrice(new 
java.math.BigDecimal("150.00"));
                        activityRate.setYouthPrice(new 
java.math.BigDecimal("120.00"));
                        
                        bundledActivity.setRatePlan(activityRate);
                        bundle.getActivities().add(bundledActivity);
                }
                
                PersistenceManager pm = PMF.createManager();
                Transaction tx = pm.currentTransaction();
                
                try {
                        bundle = pm.makePersistent(bundle);
                        tx.commit();
                }
                finally {
                        if (tx.isActive()) {
                                tx.rollback();
                        }
                        
                        pm.close();
                }
                
I get the Bundle saved just fine, but when it tries to save it's child
BundledActivity instances, it breaks.  However, when I do the same
thing through the UI of my app, I get the error when attempting to
save the Bundle (i.e. nothing gets written to the datastore, where as
in this test code above, the parent Bundle is getting written, but
none of it's children are getting written).

Of course anytime I post my code, I kind of summarize, there are
utilities that I use etc.  But I am able to reproduce the issue
without using any of my "helper" apis. I am completely open to just
sending you my code (it's all proof of concept right now, so no
disclosure issues) and you can see how all the pieces I'm using are
fitting together.

I appreciate you taking a look at this, I'd love to know if I'm doing
something wrong.
thanks,
-bryce



On Tue, Dec 1, 2009 at 11:03 AM, Max Ross (Google)
<[email protected]> wrote:
> Hi Bryce,
>
> Thanks for posting your model objects.  I'm not able to reproduce the
> exception you're reporting, but then again I'm just guessing at how you're
> populating your objects and persisting them.  Here's what I did:
>
>     Bundle b = new Bundle();
>     RatePlan rp = new RatePlan();
>     rp.setPricingModel(PricingModel.BOTH);
>     b.setRatePlan(rp);
>     b.setPricingModel(PricingModel.PER_GUEST);
>     BundledActivity ba = new BundledActivity();
>     ba.setDay(3);
>     ActivityFK activityFK = new ActivityFK();
>     activityFK.setName("harold");
>     activityFK.setPricingModel(PricingModel.PER_UNIT);
>     ba.setActivity(activityFK);
>     RatePlan anotherRatePlan = new RatePlan();
>     ba.setRatePlan(anotherRatePlan);
>     b.getActivities().add(ba);
>     beginTxn();
>     pm.makePersistent(b);
>     commitTxn();
>
> If you can tell me how what you're doing differs from what I'm doing I can
> investigate further.
>
> Thanks,
> Max
>
> On Mon, Nov 30, 2009 at 5:34 PM, bcottam <[email protected]> wrote:
>>
>> no one has any ideas on this?
>>
>> I'd really like to know if this is just a bug that will be resolved
>> (in which case I'll continue to use this data model) or if there is a
>> flaw in my data model/JDO usage.
>>
>> thanks!
>> -bryce
>>
>>
>>
>> On Nov 30, 1:21 am, bcottam <[email protected]> wrote:
>> > I'm trying to save some data in my app, quite similar to almost all
>> > other data I've previously saved.  However, I'm now getting this stack
>> > trace:
>> >
>> > java.lang.ClassCastException: oid is not instanceof
>> > javax.jdo.identity.ObjectIdentity
>> >         at
>> > com.resmark.client.model.RatePlan.jdoCopyKeyFieldsFromObjectId
>> > (RatePlan.java)
>> >         at
>> >
>> > org.datanucleus.store.mapped.mapping.PersistenceCapableMapping.setObjectAsValue
>> > (PersistenceCapableMapping.java:657)
>> >         at
>> > org.datanucleus.store.mapped.mapping.PersistenceCapableMapping.setObject
>> > (PersistenceCapableMapping.java:364)
>> >         at org.datanucleus.store.appengine.DatastoreRelationFieldManager
>> > $1.setObjectViaMapping(DatastoreRelationFieldManager.java:132)
>> >         at org.datanucleus.store.appengine.DatastoreRelationFieldManager
>> > $1.apply(DatastoreRelationFieldManager.java:108)
>> >         at
>> >
>> > org.datanucleus.store.appengine.DatastoreRelationFieldManager.storeRelations
>> > (DatastoreRelationFieldManager.java:80)
>> >         at
>> > org.datanucleus.store.appengine.DatastoreFieldManager.storeRelations
>> > (DatastoreFieldManager.java:795)
>> >         at
>> >
>> > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertPostProcess
>> > (DatastorePersistenceHandler.java:288)
>> >         at
>> >
>> > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObjects
>> > (DatastorePersistenceHandler.java:241)
>> >         at
>> > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject
>> > (DatastorePersistenceHandler.java:225)
>> >         at
>> > org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent
>> > (JDOStateManagerImpl.java:3185)
>> >         at org.datanucleus.state.JDOStateManagerImpl.makePersistent
>> > (JDOStateManagerImpl.java:3161)
>> >         at org.datanucleus.ObjectManagerImpl.persistObjectInternal
>> > (ObjectManagerImpl.java:1298)
>> >         at org.datanucleus.ObjectManagerImpl.persistObject
>> > (ObjectManagerImpl.java:1175)
>> >         at org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent
>> > (JDOPersistenceManager.java:669)
>> >         at org.datanucleus.jdo.JDOPersistenceManager.makePersistent
>> > (JDOPersistenceManager.java:694)
>> >         at com.resmark.server.model.service.BaseDataService.create
>> > (BaseDataService.java:227)
>> >         at com.resmark.server.SetupServiceImpl.updateOrCreate
>> > (SetupServiceImpl.java:120)
>> >         at com.resmark.server.SetupServiceImpl.updateOrCreateBundle
>> > (SetupServiceImpl.java:67)
>> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> >         at sun.reflect.NativeMethodAccessorImpl.invoke
>> > (NativeMethodAccessorImpl.java:39)
>> >         at sun.reflect.DelegatingMethodAccessorImpl.invoke
>> > (DelegatingMethodAccessorImpl.java:25)
>> >         at java.lang.reflect.Method.invoke(Method.java:597)
>> >         at
>> > com.google.appengine.tools.development.agent.runtime.Runtime.invoke
>> > (Runtime.java:100)
>> >         at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse
>> > (RPC.java:527)
>> >         at
>> > com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall
>> > (RemoteServiceServlet.java:166)
>> >         at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost
>> > (RemoteServiceServlet.java:86)
>> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
>> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
>> >         at
>> > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
>> > 487)
>> >         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
>> > (ServletHandler.java:1093)
>> >         at
>> > com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter
>> > (TransactionCleanupFilter.java:43)
>> >         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
>> > (ServletHandler.java:1084)
>> >         at
>> > com.google.appengine.tools.development.StaticFileFilter.doFilter
>> > (StaticFileFilter.java:121)
>> >         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
>> > (ServletHandler.java:1084)
>> >         at org.mortbay.jetty.servlet.ServletHandler.handle
>> > (ServletHandler.java:360)
>> >         at org.mortbay.jetty.security.SecurityHandler.handle
>> > (SecurityHandler.java:216)
>> >         at org.mortbay.jetty.servlet.SessionHandler.handle
>> > (SessionHandler.java:181)
>> >         at org.mortbay.jetty.handler.ContextHandler.handle
>> > (ContextHandler.java:712)
>> >         at
>> > org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
>> > 405)
>> >         at
>> > com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle
>> > (DevAppEngineWebAppContext.java:54)
>> >         at org.mortbay.jetty.handler.HandlerWrapper.handle
>> > (HandlerWrapper.java:139)
>> >         at com.google.appengine.tools.development.JettyContainerService
>> > $ApiProxyHandler.handle(JettyContainerService.java:342)
>> >         at org.mortbay.jetty.handler.HandlerWrapper.handle
>> > (HandlerWrapper.java:139)
>> >         at org.mortbay.jetty.Server.handle(Server.java:313)
>> >         at
>> > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
>> > 506)
>> >         at org.mortbay.jetty.HttpConnection$RequestHandler.content
>> > (HttpConnection.java:844)
>> >         at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
>> >         at
>> > org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
>> >         at
>> > org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
>> >         at org.mortbay.io.nio.SelectChannelEndPoint.run
>> > (SelectChannelEndPoint.java:396)
>> >         at org.mortbay.thread.BoundedThreadPool$PoolThread.run
>> > (BoundedThreadPool.java:442)
>> >
>> > I've seen this come up when a data model has a many-to-one
>> > relationship and a one-to-one relationship with the same data type,
>> > but I'm not doing that.
>> >
>> > here is the code referenced:
>> > @PersistenceCapable(identityType=IdentityType.APPLICATION)
>> > public class Bundle  implements Serializable {
>> >         @PrimaryKey
>> >         @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
>> >         private Key id;
>> >
>> >         @Persistent
>> >         private String name;
>> >         @Persistent
>> >         private Text description;
>> >
>> >         @Persistent
>> >         private RatePlan ratePlan;
>> >         @Persistent
>> >         private PricingModel pricingModel;
>> >
>> >         @Persistent
>> >         private List<BundledActivity> activities = new
>> > ArrayList<BundledActivity>();
>> >         ....
>> >
>> > }
>> >
>> > @PersistenceCapable(identityType=IdentityType.APPLICATION)
>> > public class RatePlan implements Serializable {
>> >
>> >         @PrimaryKey
>> >         @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
>> >         public Key id;
>> >
>> >         @Persistent
>> >         private String name;
>> >
>> >         @Persistent
>> >         private BigDecimal adultPrice;
>> >         @Persistent
>> >         private BigDecimal youthPrice;
>> >         @Persistent
>> >         private BigDecimal unitPrice;
>> >
>> >         @Persistent
>> >         private PricingModel pricingModel;
>> >
>> >         @Persistent
>> >         private boolean active = true;
>> >         .....
>> >
>> > }
>> >
>> > @PersistenceCapable(identityType=IdentityType.APPLICATION)
>> > public class BundledActivity implements Serializable {
>> >
>> >         @PrimaryKey
>> >         @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
>> >         private Key id;
>> >
>> >         @Embedded
>> >         @Persistent
>> >         private ActivityFK activity;
>> >         @Persistent
>> >         private RatePlan ratePlan;
>> >         @Persistent
>> >         private int day;
>> >
>> >         @Persistent
>> >         @Extension(vendorName="datanucleus", key="gae.parent-pk",
>> > value="true")
>> >         private Key bundleId;
>> >         .....
>> >
>> > }
>> >
>> > @PersistenceCapable(identityType=IdentityType.NONDURABLE)
>> > public class ActivityFK  implements Serializable {
>> >
>> >         @Persistent
>> >         private Key key;
>> >         @Persistent
>> >         private String name;
>> >         @Persistent
>> >         private PricingModel pricingModel;
>> >         ....
>> >
>> > }
>> >
>> > public enum PricingModel implements Serializable {
>> >         PER_GUEST, PER_UNIT, BOTH;
>> >
>> > }
>> >
>> > perhaps there's something I'm missing about the model.  I've done
>> > almost the same thing in most of my other data model objects and their
>> > relationships.  I think about the only thing that's different here is
>> > the @Extension annotation, but that's not where the error is
>> > happening.  Any suggestions would be very welcome.
>> >
>> > Thanks!
>> > -bryce
>>
>> --
>>
>> 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
>> [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>
>>
>
> --
>
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>

--

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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to