I'm writing a simple JUnit test class which uses the utilities mentioned 
here: http://code.google.com/appengine/docs/java/tools/localunittesting.html  
I'm stuck trying to persist more than one instance of simple entity in a 
single transaction.  Every time I run the test shown below, it fails with:

    Caused by: java.lang.IllegalArgumentException: can't operate on multiple 
entity groups in a single transaction. found both Element {

  type: "Company"

  id: 1

}

 and Element {

  type: "Company"

  id: 2

}

I have one entity class "Company" which looks something like this:

   @Entity

public class Company {


  @Id

  @GeneratedValue(strategy = GenerationType.IDENTITY)

  private Key id;

  @Basic

  private String name;


  public Company(String name) {

    setName(name);

  }


  public Key getId() {

    return id;

  }


  public String getName() {

    return name;

  }


  public void setName(String name) {

    this.name = name;

  }

}


My test class (mostly taken from the examples in the google 
documentation) does the following within my Eclipse environment:


   public class LocalDatastoreTest {


  private final LocalServiceTestHelper helper = new LocalServiceTestHelper(
new LocalDatastoreServiceTestConfig());

  EntityManager em = EMF.get().createEntityManager();


  @Before

  public void setUp() {

    helper.setUp();

  }


  @After

  public void tearDown() {

    helper.tearDown();

  }


  @Test

  public void testPersist() {

    em.getTransaction().begin();

    em.persist(new Company("Best Buy"));

    em.persist(new Company("Trader Joe's"));

    em.persist(new Company("Jack In The Box"));

    em.getTransaction().commit();

  }

}

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/R9G0Gz2av_EJ.
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.

Reply via email to