The container.persistIfNotAlready(...) actually queues up the persist
object; the persist normally only happens on commit, at the end of the
request.
But you can force the persist using:
container.flush();
After that you should be able to read the Id as Martin suggested.
HTH
Dan
On 12 March 2015 at 09:28, Lechner Andreas <[email protected]> wrote:
> Hi Martin,
>
> everytime when I use JDOHelper.getObjectId on my stored Object
> after container.persistIfNotAlready
> I get a NULL value.
>
> The instance of PersistenceCapable is true.
>
> best regards
> Andreas
>
>
>
> ----- Ursprüngliche Mail -----
> Von: "Martin Grigorov" <[email protected]>
> An: "users" <[email protected]>
> Gesendet: Mittwoch, 11. März 2015 17:07:30
> Betreff: Re: persist a new Object
>
> Hi,
>
> I think you need something like:
>
> if (!(this instanceof javax.jdo.spi.PersistenceCapable)) {
> return null;
> }
> OIDImpl longIdentity = (OIDImpl) JDOHelper.getObjectId(this);
> return longIdentity.getKeyValue();
>
> Martin Grigorov
> Funemployed! Available for hire!
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Wed, Mar 11, 2015 at 5:58 PM, Lechner Andreas <[email protected]>
> wrote:
>
> > Hi all,
> >
> > Maybe i have overseen something.
> >
> > I want to persist MyObject.
> > It has a member ID which is a @PrimaryKey and @Persistent(valueStrategy =
> > IdGeneratorStrategy.IDENTITY).
> >
> > When id do:
> > PersistenceManager jdoPersistenceManager =
> > isisJdoSupport.getJdoPersistenceManager();
> > MyObject persistedObject =
> jdoPersistenceManager.makePersistent(myObject);
> >
> > I get an ID filled in the returned persistedObject.
> >
> > How do i get the ID of the fresh persisted MyObject when I use the
> > injected DomainObjectContainer container?
> > container.persistIfNotAlready(settingItem);
> >
> > I need the ID and want to use the implemented soloution from Apache ISIS
> > and not to
> > implement my own soloution.
> >
> > best regards
> > Andreas
> >
>