I don't use JPA myself, so I don't have a code example for you, but you 
have the right concept at the end of your post. In order to be in the same 
Entity Group, entities must share the same Parent entity. You should make 
sure that this is actually sensible in your data model, and not simply do 
it to support arbitrary transactions. You can also use cross-group 
transactions, but that only supports 5 different entity groups per 
transaction.

I think that in JPA it is actually a little messier to use parent entities 
than with some other persistence mechanisms. If you aren't too far along, 
and you don't mind using an app engine specific library, I would encourage 
you to look at Objectify: http://code.google.com/p/objectify-appengine/


On Thursday, July 12, 2012 10:10:54 AM UTC-4, Peter wrote:
>
> Hi
>
> I'm using JPA in my application. Yesterday I tried to delete some Entities 
> with a same class in one transaction, but I got an exception which said 
> that I can not do this in one transaction as they are in a different entity 
> group. I thought If I persist two entities with the same class they will be 
> in the same entity group, but now I know that they won't. 
>
> The question is how can I persist two entities to be in the same group? 
>
> My  entity looks like this:
> @Entity
> public class SomeEntity {
>
> @Id
> @GeneratedValue(strategy = GenerationType.IDENTITY)
> protected Key key;
>
> }
>
> When I persist them the key is set automatically:
> entityManager.persist(someEntityObject);
>
> Deleting them:
> ... EntityManager em;
> ... List<SomeEntity> toDelete;
> EntityTransaction tx = em.getTransaction();
> try {
> tx.begin();
>
> for (SomeEntity entity : toDelete) {
>
> em.remove(entity);
>
> } 
>
> tx.commit();
> } finally {
> if (tx.isActive()) {
> tx.rollback();
> }
> em.close();
> }
> I saw somehow I can set a parent key to the keys but I think in this way 
> I'll loose the automatic id generation.
> Is there a good way to resolve this problem?
>
> Thanks,
> Peter
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/EtKQdwJsa4IJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to