Can't hurt...
I define transactions for all my datastore access paths.

Thats the only way I can keep track of which entity is in context.
pm .currentTransaction.begin()
pm .currentTransaction.commit()

I'm also able to rollback() database access and not have the overhead of a
commit cleanup.
pm .currentTransaction.rollback()


On Mon, Oct 25, 2010 at 3:45 PM, Cosmin Stefan <
cosmin.stefandob...@gmail.com> wrote:

> Hey,
>
> The thing is I don't have a transaction. And, I also am using
> IdentityType.Datastore, as I need the id to be generated by the
> datastore.
>
> Anyway, this is what I currently have (and doesn't properly work):
>
> @PersistenceCapable(detachable="true")
> @Embeddable
> public class GMeeting
> {
> ...
>         /** The id. */
>    @PrimaryKey
>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>    private Long id;
> ...}
>
> and the using code:
> {
> ....
>                 meeting=new Meeting();
>                //Adding the new meeting
>                pm.makePersistent(meeting);
>                meeting=pm.detachCopy(meeting);
>                Long meetingID=meeting.getId();
> ....}
>
> Anyway, this still doesn't work. Do I need to use a transaction?
>
> Thanks,
> Cosmin
>
>
> On Oct 23, 2:09 am, "A. Stevko" <andy.ste...@gmail.com> wrote:
> > In order to make the object accessible after the commit() you need to
> make
> > it detatchable.
> >
> > @PersistenceCapable(identityType = IdentityType.APPLICATION,
> > detachable="true")
> > public class Meeting
> >
> > Then used this...
> > pm.makePersistent(meeting);
> > Long meetingID=meeting.getId();
> >
> > On Fri, Oct 22, 2010 at 3:19 PM, Cosmin Stefan <
> >
> > cosmin.stefandob...@gmail.com> wrote:
> > > And I really want to emphasize that this doesn't happen EVERY time.
> >
> > > Thanks and sorry for replying again!
> >
> > > On Oct 23, 1:17 am, Cosmin Stefan <cosmin.stefandob...@gmail.com>
> > > wrote:
> > > > Hey,
> >
> > > > Unfortunately, the first solution you suggested does not work and I
> > > > don't really need a transaction for what I want.
> >
> > > > The thing is that I somehow need to persist the new entity and find
> > > > out it's key. How can I do this? Does anybody have an ideea?
> >
> > > > Thanks a lot,
> > > > Cosmin
> >
> > > > On Oct 22, 9:18 am, Ian Marshall <ianmarshall...@gmail.com> wrote:
> >
> > > > > Have you tried replacing
> >
> > > > >   pm.makePersistent(meeting);
> > > > >   Long meetingID=meeting.getId();
> >
> > > > > with
> >
> > > > >   meeting = pm.makePersistent(meeting);
> > > > >   Long meetingID=meeting.getId();
> >
> > > > > and see if this solves your problem. You might also want to commit
> > > > > your transaction if you are doing this persistence in a transaction
> > > > > before testing your meeting's ID (the ID might not get allocated
> until
> > > > > transaction committal).
> >
> > > > > On Oct 20, 11:19 pm, Cosmin Stefan <cosmin.stefandob...@gmail.com>
> > > > > wrote:
> >
> > > > > > Hey,
> >
> > > > > > I have encountered a weird case while trying to create a new
> entity
> > > in
> > > > > > the database:
> >
> > > > > > I have this code:
> >
> > > > > >         Meeting meeting=new Meeting(...)
> > > > > >         pm.makePersistent(meeting);
> > > > > >         Long meetingID=meeting.getId();
> >
> > > > > >         if(meetingID==null)
> > > > > >                 throw new Exception("meetingID is null...");
> >
> > > > > > and in the Meeting Class:
> > > > > >         /** The id. */
> > > > > >        @PrimaryKey
> > > > > >        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> > > > > >        private Long id;
> > > > > > so the id is Long.
> >
> > > > > > The problem is that sometimes the above code throws an exception,
> > > some
> > > > > > other times it doesn't... What am I doing wrong?
> >
> > > > > > Thanks!
> >
> > > --
> > > 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<google-appengine-java%2bunsubscr...@googlegroups.com>
> <google-appengine-java%2bunsubscr...@googlegroups.com<google-appengine-java%252bunsubscr...@googlegroups.com>
> >
> > > .
> > > 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
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> 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 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