Thanks leszek.  We are going do what you suggest (the JPA
equivalent).

In order to generate the unique part of the child's key, I'm wondering
if there is a way to use sequence in JPA.  In JDO, I think you can do
something like:

Sequence seq = pm.getSequence("child.sequence");
long id = seq.nextValue();

Does anyone know if  there is an equivalent to this in JPA, i.e. to
get direct access to a sequence?

Thanks,
Len


On Oct 20, 4:04 am, leszek <leszek.ptokar...@gmail.com> wrote:
> Look at the code snippet below:
>
> // entity class
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class ChildEnt {
>
>     @PrimaryKey
>     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> //   �...@extension(vendorName="datanucleus", key="gae.encoded-
> pk",value="true")
>     private Key encodedKey;
>
>     private String info;
>
>         public Key getEncodedKey() {
>                 return encodedKey;
>         }
>
>         public void setEncodedKey(Key encodedKey) {
>                 this.encodedKey = encodedKey;
>         }
>
>         public String getInfo() {
>                 return info;
>         }
>
>         public void setInfo(String info) {
>                 this.info = info;
>         }
>
> }
>
> // transaction code
>
>         PersistenceManager pm = PMF.get().getPersistenceManager();
>
>         Key parkey = KeyFactory.createKey("Parent","P01");
>
>         ChildEnt e1 = new ChildEnt();
>         ChildEnt e2 = new ChildEnt();
>         ChildEnt e3 = new ChildEnt();
>         Key k1 = KeyFactory.createKey(parkey,ChildEnt.class.getSimpleName(),
> 1);
>         Key k2 = KeyFactory.createKey(parkey,ChildEnt.class.getSimpleName(),
> 2);
>         Key k3 = KeyFactory.createKey(parkey,ChildEnt.class.getSimpleName(),
> 3);
>         e1.setEncodedKey(k1);
>         e1.setInfo("info1");
>         e2.setEncodedKey(k2);
>         e2.setInfo("info2");
>         e3.setEncodedKey(k3);
>         e3.setInfo("info3");
>         pm.currentTransaction().begin();
>         pm.makePersistent(e1);
>         pm.makePersistent(e2);
>         pm.makePersistent(e3);
>         pm.currentTransaction().commit();
>         pm.close();
--~--~---------~--~----~------------~-------~--~----~
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-java@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