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) {
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