使用JPA在GAE中插入不同类型的实体

时间:2013-07-31 05:53:10

标签: google-app-engine google-cloud-datastore

我是GAE和Datastore的新手

我正在尝试使用JPA在GAE数据存储区中插入不同类型的实体。 例如,我必须插入Employee,EmployeePersonalInfo(具有雇员密钥),EmployeeAddressInfo(具有EmployeePersonalInfo密钥)。在这里,我没有在实体之间创建任何外键关系。我的实体将如下所示

public class Employee{

private String name;
private Key key;
}

public class EmployeePersonalInfo{
private String emailAddress;
private Key key;
private Key employeeKey;
}

public class EmployeeAddressInfo{
private String cityName;
private Key key;
private Key employeePersonalInfoKey;
}

i am trying to insert around 5 record on each table like

public class EmployeeController{

/*This method will be called for 5 times*/
public void insertEmployeeDetails(Employee emp,EmployeePersonalInfo perInfo,EmployeeAddressInfo addressInfo){
employeeDao.save(emp);
employeePersonalInfoDao.save(perInfo);
employeeAddressInfoDao.save(addressInfo);
}
}

每当调用转到DAO类的Save方法时,我将打开EntityManager对象,并在操作后关闭。

public void save(Employee emp){
        EntityManager em = EMFService.get().createEntityManager();
                em.save(emp);
                em.close();

}

有时我会得到像

这样的例外
Caused by: java.lang.IllegalArgumentException: cross-group transaction need to be explicitly specified, see TransactionOptions.Builder.withXG

我已经看到了很多这个问题的解决方案,但我无法理解真正的问题和解决方案是什么。请帮帮我

0 个答案:

没有答案