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 < [email protected]> 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 <[email protected]> > 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 <[email protected]> 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 <[email protected]> > > > 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 > [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-appengine-java%[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.
