On 19 Jul., 17:18, Kesava Neeli <[email protected]> wrote:
> Hi,
> Any one has suggestions to my issue?
I've tried to reproduce your problem with the appengine-datanucleus
1.0.9 plugin, but with no success.
The following tests are passing. Did I miss something? Can you modify
the test to show what is going wrong in your case?
>----------------- DuplicateListEntriesIssueTest --------------------<
package org.datanucleus.store.appengine;
import java.util.List;
import org.datanucleus.test.MyDataObject;
import org.datanucleus.test.SmartItem;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
public class DuplicateListEntriesIssueTest extends JPATestCase {
public void test01() throws EntityNotFoundException {
// <persistence-unit
name="transactional_ds_non_transactional_ops_not_allowed">
//
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</
provider>
// <properties>
// <property name="datanucleus.ConnectionURL"
value="appengine"/>
// <property
name="datanucleus.metadata.allowLoadAtRuntime" value="true"/>
// <property
name="datanucleus.appengine.ignorableMetaDataBehavior" value="ERROR"/>
// <property
name="datanucleus.appengine.storageVersion"
value="WRITE_OWNED_CHILD_KEYS_TO_PARENTS"/>
// </properties>
// </persistence-unit>
MyDataObject newData = new MyDataObject();
newData.deviceId = "123";
newData.getData().add(new SmartItem("list1"));
newData.getData().add(new SmartItem("list2"));
Key key =
KeyFactory.createKey(MyDataObject.class.getSimpleName(),
newData.deviceId);
newData.key = key;
beginTxn();
em.persist(newData);
commitTxn();
Entity e = ds.get(key);
assertEquals(2, ((List<?>)e.getProperty("data")).size());
beginTxn();
newData = em.find(MyDataObject.class, key);
newData.getData().add(new SmartItem("list3"));
assertEquals(3, newData.getData().size());
em.persist(newData);
commitTxn();
e = ds.get(key);
assertEquals(3, ((List<?>)e.getProperty("data")).size());
beginTxn();
newData = em.find(MyDataObject.class, key);
assertData(newData.getData(), "list1", "list2", "list3");
commitTxn();
}
public void test02() throws EntityNotFoundException {
// <persistence-unit
name="nontransactional_ds_non_transactional_ops_allowed">
//
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</
provider>
// <properties>
// <property
name="datanucleus.NontransactionalRead" value="true"/>
// <property
name="datanucleus.NontransactionalWrite" value="true"/>
// <property name="datanucleus.ConnectionURL"
value="appengine"/>
// <property
name="datanucleus.appengine.autoCreateDatastoreTxns" value="false"/>
// <property
name="datanucleus.metadata.allowLoadAtRuntime" value="true"/>
// <property
name="datanucleus.appengine.ignorableMetaDataBehavior" value="ERROR"/>
// <property
name="datanucleus.appengine.storageVersion"
value="WRITE_OWNED_CHILD_KEYS_TO_PARENTS"/>
// </properties>
// </persistence-unit>
switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
MyDataObject newData = new MyDataObject();
newData.deviceId = "123";
newData.getData().add(new SmartItem("list1"));
newData.getData().add(new SmartItem("list2"));
Key key =
KeyFactory.createKey(MyDataObject.class.getSimpleName(),
newData.deviceId);
newData.key = key;
em.persist(newData);
newData.getData().add(new SmartItem("list3"));
em.persist(newData);
em.close();
Entity e = ds.get(key);
assertEquals(3, ((List<?>)e.getProperty("data")).size());
em = emf.createEntityManager();
newData = em.find(MyDataObject.class, key);
assertData(newData.getData(), "list1", "list2", "list3");
}
private void assertData(List<SmartItem> data, String... expected) {
assertEquals(expected.length, data.size());
for (int i = 0; i < expected.length; i++) {
data.get(i).getStr().equals(expected[i]);
}
}
}
>----------------- MyDataObject --------------------<
package org.datanucleus.test;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import com.google.appengine.api.datastore.Key;
@Entity
public class MyDataObject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Key key;
public String deviceId;
// some persistent fields of standard types
public int intfield;
@Basic
@OneToOne(cascade =
{ CascadeType.PERSIST,CascadeType.REFRESH,CascadeType.REMOVE }, fetch
= FetchType.LAZY)
public List<SmartItem> data;
// standard getters/setters
public MyDataObject() {
this.data = new ArrayList<SmartItem>();
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public int getIntfield() {
return intfield;
}
public void setIntfield(int intfield) {
this.intfield = intfield;
}
public List<SmartItem> getData() {
return data;
}
}
>----------------- SmartItem --------------------<
package org.datanucleus.test;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import com.google.appengine.api.datastore.Key;
@Entity
public class SmartItem {
private static final long serialVersionUID = 4428700412206745337L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Key key;
// bunch of persistent fields
String str;
public SmartItem(String str) {
this.str = str;
}
public Key getKey() {
return key;
}
public String getStr() {
return str;
}
}
Rolf
--
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 [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.