[appengine-java] Re: JPA: Query contains stale data (bug or future)?

2010-04-13 Thread danblack
Can anyone help me?

On Apr 9, 6:47 pm, Denis Chernyshov firewor...@gmail.com wrote:
 Here is my full log.

 09.04.2010 12:20:15 org.datanucleus.ObjectManagerImpl init
 FINE: Object Manager org.datanucleus.objectmanageri...@1dfa916 opened for
 datastore org.datanucleus.store.appengine.datastoremana...@13a1505
 09.04.2010 12:20:15 org.datanucleus.ObjectManagerImpl initialiseLevel1Cache
 FINE: Level 1 Cache of type weak initialised
 09.04.2010 12:20:15 org.datanucleus.transaction.Transaction init
 FINE: Transaction created [DataNucleus Transaction, ID=Xid=, enlisted
 resources=[]]
 09.04.2010 12:20:15 org.datanucleus.TransactionImpl internalBegin
 FINE: Transaction begun for ObjectManager
 org.datanucleus.objectmanageri...@1dfa916 (optimistic=true)
 09.04.2010 12:20:15
 org.datanucleus.store.appengine.jpa.DatastoreEntityTransactionImpl begin
 FINE: Started new datastore transaction: 2
 09.04.2010 12:20:15 org.datanucleus.ObjectManagerImpl getObjectFromCache
 FINE: Object with id
 ru.englishvocabulary.model.test.Container:Container(756) not found in
 Level 1 cache [cache size = 0]
 09.04.2010 12:20:15 org.datanucleus.ObjectManagerImpl putObjectIntoCache
 FINE: Object ru.englishvocabulary.model.test.contai...@a80631
 (id=ru.englishvocabulary.model.test.Container:Container(756)) added to
 Level 1 cache (loadedFlags=[NY])
 09.04.2010 12:20:15 org.datanucleus.transaction.Transaction enlistResource
 FINE: Running enlist operation on resource:
 org.datanucleus.store.appengine.datastorexaresou...@787691, error code
 TMNOFLAGS and transaction: [DataNucleus Transaction, ID=Xid=, enlisted
 resources=[]]
 09.04.2010 12:20:15 org.datanucleus.ConnectionManagerImpl allocateConnection
 FINE: Connection added to the pool :
 org.datanucleus.store.appengine.datastoreconnectionfactoryimpl$datastoremanagedconnect...@1392dd5
 09.04.2010 12:20:15
 org.datanucleus.store.appengine.DatastorePersistenceHandler get
 FINE: Getting entity of kind Container with key Container(756)
 09.04.2010 12:20:15 org.datanucleus.state.LifeCycleState changeState
 FINE: Object ru.englishvocabulary.model.test.contai...@a80631
 (id=ru.englishvocabulary.model.test.Container:Container(756)) has a
 lifecycle change : HOLLOW-P_NONTRANS

 // My Item
 09.04.2010 12:20:15 org.datanucleus.ObjectManagerImpl getObjectFromCache
 FINE: Object with id
 ru.englishvocabulary.model.test.Item:Container(756)/Item(761) not found in
 Level 1 cache [cache size = 1]
 09.04.2010 12:20:15 org.datanucleus.ObjectManagerImpl putObjectIntoCache
 FINE: Object ru.englishvocabulary.model.test.i...@e61a90
 (id=ru.englishvocabulary.model.test.Item:Container(756)/Item(761)) added
 to Level 1 cache (loadedFlags=[NYN])
 09.04.2010 12:20:15 org.datanucleus.state.LifeCycleState changeState
 FINE: Object ru.englishvocabulary.model.test.i...@e61a90
 (id=ru.englishvocabulary.model.test.Item:Container(756)/Item(761)) has a
 lifecycle change : HOLLOW-P_NONTRANS
 09.04.2010 12:20:15 org.datanucleus.ConnectionManagerImpl allocateConnection
 FINE: Connection found in the pool :
 org.datanucleus.store.appengine.datastoreconnectionfactoryimpl$datastoremanagedconnect...@1392dd5
 09.04.2010 12:20:15 org.datanucleus.ConnectionManagerImpl allocateConnection
 FINE: Connection found in the pool :
 org.datanucleus.store.appengine.datastoreconnectionfactoryimpl$datastoremanagedconnect...@1392dd5
 09.04.2010 12:20:15
 org.datanucleus.store.appengine.DatastorePersistenceHandler get
 FINE: Getting entity of kind Item with key Container(756)/Item(761)

 //  Change my item
 09.04.2010 12:20:15 org.datanucleus.state.LifeCycleState changeState
 FINE: Object ru.englishvocabulary.model.test.i...@e61a90
 (id=ru.englishvocabulary.model.test.Item:Container(756)/Item(761)) has a
 lifecycle change : P_NONTRANS-P_DIRTY
 09.04.2010 12:20:15 org.datanucleus.ObjectManagerImpl enlistInTransaction
 FINE: Object ru.englishvocabulary.model.test.i...@e61a90
 (id=com.google.appengine.api.datastore.Key:Container(756)/Item(761))
 enlisted in transactional cache
 09.04.2010 12:20:15 ru.englishvocabulary.bl.local.test.LocalService
 changeItems
 SEVERE: changed item: i...@e61a90 [key=Container(756)/Item(761), value=xxx]
 09.04.2010 12:20:15 org.datanucleus.ConnectionManagerImpl allocateConnection
 FINE: Connection found in the pool :
 org.datanucleus.store.appengine.datastoreconnectionfactoryimpl$datastoremanagedconnect...@1392dd5
 09.04.2010 12:20:15 org.datanucleus.sco.backed.List init
 FINE: Object ru.englishvocabulary.model.test.contai...@a80631 field
 items is replaced by a SCO wrapper of type
 org.datanucleus.sco.backed.List [cache-values=true, lazy-loading=true,
 queued-operations=true, allow-nulls=false]
 09.04.2010 12:20:15 org.datanucleus.sco.backed.List loadFromStore
 FINE: Object ru.englishvocabulary.model.test.contai...@a80631 field
 items loading contents to SCO wrapper from the datastore
 09.04.2010 12:20:15
 org.datanucleus.store.appengine.DatastoreElementContainerStoreSpecialization
 prepareChildrenQuery
 FINE: 

[appengine-java] Re: JPA: Query contains stale data (bug or future)?

2010-04-09 Thread danblack
I'm not serializing List's data in a single column so I don't have to
force entities to update, if I'm not mistaken.

On Apr 7, 4:15 am, Ikai L (Google) ika...@google.com wrote:
 It looks like you are changing the elements of the List themselves and not
 the List. You'll have to mark the object as dirty:

 https://groups.google.com/group/google-appengine-java/browse_thread/t...

 https://groups.google.com/group/google-appengine-java/browse_thread/t...I'm
 not completely sure this is what's going on here, as I just did a quick read
 through of your code. Can you give this a try?



 On Fri, Mar 26, 2010 at 11:47 PM, danblack firewor...@gmail.com wrote:
  Hello.
  I'm using JPA support for managing the App Engine datastore.
  And I've got some problems.

  I've got an entity Container than contains entities Item(s).
  Here is my actions.
  I starts transaction then updates entity then flush updates to
  database.
  Than I gets all entities Item(s) for a container which contains my
  updated Item.
  But the list of retrieved items contains Item that does not have my
  changes.
  What is wrong with my code???

  I've modelled this problem. (see code)

  @Entity
  public class Container implements Serializable {

         private static final long serialVersionUID = 1L;

        �...@id
        �...@generatedvalue(strategy = GenerationType.IDENTITY)
         private Key key;

        �...@onetomany(mappedBy = container, fetch = FetchType.LAZY)
         private ListItem items = new ArrayListItem();

         public void setKey(Key key) {
                 this.key = key;
         }

         public Key getKey() {
                 return key;
         }

         public void setItems(ListItem items) {
                 this.items = items;
         }

         public ListItem getItems() {
                 return items;
         }

  }

  @Entity
  public class Item implements Serializable {

         private static final long serialVersionUID = 1L;

        �...@id
        �...@generatedvalue(strategy = GenerationType.IDENTITY)
         private Key key;

        �...@manytoone(fetch = FetchType.LAZY)
         private Container container;

        �...@column
         private String value;

         public void setKey(Key key) {
                 this.key = key;
         }

         public Key getKey() {
                 return key;
         }

         public void setContainer(Container container) {
                 this.container = container;
         }

         public Container getContainer() {
                 return container;
         }

         public void setValue(String value) {
                 this.value = value;
         }

         public String getValue() {
                 return value;
         }

        �...@override
         public String toString() {
                 return Item [key= + key + , value= + value + ];
         }
  }

  @Service(TestLocalService)
  public class LocalService {

         protected final Log logger = LogFactory.getLog(getClass());

        �...@autowired
        �...@qualifier(jpaTemplate)
         protected JpaTemplate jpaTemplate;

        �...@transactional(propagation = Propagation.REQUIRED)
         public Key createContainer() {
                 Container container = new Container();
                 jpaTemplate.persist(container);
                 jpaTemplate.flush();
                 logger.fatal(new container + container.getKey());
                 return container.getKey();
         }

        �...@transactional(propagation = Propagation.REQUIRED)
         public Key generateItems(Key containerKey) {
                 Container container = jpaTemplate.find(Container.class,
  containerKey);
                 Key key = null;
                 for (int i = 0; i  5; i++) {
                         Item item = new Item();
                         item.setContainer(container);
                         item.setValue(Integer.toString(i));
                         jpaTemplate.persist(item);
                         jpaTemplate.flush();
                         key = item.getKey();
                         logger.fatal(new item + item);
                 }
                 return key;
         }

        �...@transactional(propagation = Propagation.REQUIRED)
         public void changeItems(Key containerKey, Key itemKey) {
                 Container container = jpaTemplate.find(Container.class,
  containerKey);
                 Item changedItem = jpaTemplate.find(Item.class, itemKey);
                 changedItem.setValue(xxx); //
  ---
  PROBLEM HERE
                 jpaTemplate.flush();
                 logger.fatal(changed item:  + changedItem);
                 for (Item item : container.getItems()) {
                         logger.fatal(list item:  + item); //
   PROBLEM
  HERE
                 }
         }

         public static void

[appengine-java] Re: JPA: Query contains stale data (bug or future)?

2010-04-09 Thread danblack
Do I have to do something like that?

// Update one side of the relation
changedItem.setValue(xxx);

// Than update another side of the relation
ListItem items = changedItem.getContainer().getItems();
for (Item item: items) {
  if (item.getKey().equals(changedItem.getKey())) {
item.setValue(changedItem.getValue());
break;
  }
}

On Apr 9, 1:21 pm, datanucleus andy_jeffer...@yahoo.com wrote:
  I'm not serializing List's data in a single column so I don't have to
  force entities to update, if I'm not mistaken.

 You are setting only one side of a relation from the code you present.
 If the relation is bidirectional then you ought to set BOTH sides. JPA
 does not come with managed relations.

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: JPA: Query contains stale data (bug or future)?

2010-04-09 Thread danblack
I think you've misunderstood where problem is.
I don't have a problem with persisting items, I have a problem with
changing item and getting my changes back.
Problem is in this code.

public void changeItems(Key containerKey, Key itemKey) {
// START TRANSACTION
Container container = jpaTemplate.find(Container.class,
containerKey);
Item changedItem = jpaTemplate.find(Item.class, itemKey);
changedItem.setValue(xxx); // -- CHANGE ITEM VALUE
jpaTemplate.flush();
logger.fatal(changed item:  + changedItem);
for (Item item : container.getItems()) {
// Query returns items and one of the items has beed
changed above
logger.fatal(list item:  + item); // -- ITEM
DOES NOT CONTAIN CHANGES MADE ABOVE
}
// COMMIT TRANSACTION
}



On Apr 9, 3:53 pm, datanucleus andy_jeffer...@yahoo.com wrote:
 I refer to your method generateItems(Key containerKey) where you do

 Item item = new Item();
 item.setContainer(container);
 item.setValue(Integer.toString(i));
 em.persist(item);

 Where did you put the item in the List exactly? You set the owner of
 the item as this container, great, but it's not in the List. Any List
 has ordering and the above will at best have it in the List
 somewhere, and at worst just not be present in the List ... since
 you didn't add it. i.e container.getItems().add(item)

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Query returns unchanged data

2010-04-08 Thread danblack
Hello.
I'm using JPA for the App Engine datastore.
And I've got some problems.

I've got an entity Container than contains entities Item(s).
Here is my actions.
I start transaction then update entity then flush updates to database.
Then I get all entities of class Item(s) for a container which
contains my updated Item.
But the list of retrieved items contains Item that does not have my
changes.
What is wrong with my code???


I've modelled this problem. (see code)

@Entity
public class Container implements Serializable {

   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Key key;

   @OneToMany(mappedBy = container, fetch = FetchType.LAZY)
   private ListItem items = new ArrayListItem();

   public void setKey(Key key) {
   this.key = key;
   }

   public Key getKey() {
   return key;
   }

   public void setItems(ListItem items) {
   this.items = items;
   }

   public ListItem getItems() {
   return items;
   }

}

@Entity
public class Item implements Serializable {

   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Key key;

   @ManyToOne(fetch = FetchType.LAZY)
   private Container container;

   @Column
   private String value;

   public void setKey(Key key) {
   this.key = key;
   }

   public Key getKey() {
   return key;
   }

   public void setContainer(Container container) {
   this.container = container;
   }

   public Container getContainer() {
   return container;
   }

   public void setValue(String value) {
   this.value = value;
   }

   public String getValue() {
   return value;
   }

   @Override
   public String toString() {
   return Item [key= + key + , value= + value + ];
   }
}

@Service(TestLocalService)
public class LocalService {

   protected final Log logger = LogFactory.getLog(getClass());


   public Key createContainer() {
   em.getTransaction().begin();
   Container container = new Container();
   em.persist(container);
   em.flush();
   logger.fatal(new container + container.getKey());
   em.getTransaction().commit();
   return container.getKey();
   }

   public Key generateItems(Key containerKey) {
   em.getTransaction().begin();
   Container container = em.find(Container.class,
containerKey);
   Key key = null;
   for (int i = 0; i  5; i++) {
   Item item = new Item();
   item.setContainer(container);
   item.setValue(Integer.toString(i));
   em.persist(item);
   em.flush();
   key = item.getKey();
   logger.fatal(new item + item);
   }
   em.getTransaction().commit();
   return key;
   }

   public void changeItems(Key containerKey, Key itemKey) {
   em.getTransaction().begin();
   Container container = em.find(Container.class,
containerKey);
   Item changedItem = em.find(Item.class, itemKey);
   changedItem.setValue(xxx); //
---
PROBLEM HERE
   em.flush();
   logger.fatal(changed item:  + changedItem);
   for (Item item : container.getItems()) {
   logger.fatal(list item:  + item); //
--- PROBLEM HERE (Item contains a
stale value of the field value)
   }
   em.getTransaction().commit();
   }

   public static void testListSync(LocalService service) {
   // MAIN TEST
   Key containerKey = service.createContainer();
   Key itemKey = service.generateItems(containerKey);
   service.changeItems(containerKey, itemKey);
   }
}


EXECUTION LOG

### CALL createContainer
datastore_v3.BeginTransaction
datastore_v3.Put
datastore_v3.Commit

## LOG createContainer
SEVERE: new containerContainer(684)

### CALL generateItems
datastore_v3.BeginTransaction
datastore_v3.Get
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Commit

### LOG generateItems
SEVERE: new itemItem [key=Container(684)/Item(685), value=0]
SEVERE: new itemItem [key=Container(684)/Item(686), value=1]
SEVERE: new itemItem [key=Container(684)/Item(687), value=2]
SEVERE: new itemItem [key=Container(684)/Item(688), value=3]
SEVERE: new itemItem [key=Container(684)/Item(689), value=4]

### CALL changeItems
datastore_v3.BeginTransaction
datastore_v3.Get
datastore_v3.Get

[appengine-java] JPA: Query contains stale data (bug or future)?

2010-03-29 Thread danblack
Hello.
I'm using JPA support for managing the App Engine datastore.
And I've got some problems.

I've got an entity Container than contains entities Item(s).
Here is my actions.
I starts transaction then updates entity then flush updates to
database.
Than I gets all entities Item(s) for a container which contains my
updated Item.
But the list of retrieved items contains Item that does not have my
changes.
What is wrong with my code???


I've modelled this problem. (see code)

@Entity
public class Container implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;

@OneToMany(mappedBy = container, fetch = FetchType.LAZY)
private ListItem items = new ArrayListItem();

public void setKey(Key key) {
this.key = key;
}

public Key getKey() {
return key;
}

public void setItems(ListItem items) {
this.items = items;
}

public ListItem getItems() {
return items;
}

}

@Entity
public class Item implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;

@ManyToOne(fetch = FetchType.LAZY)
private Container container;

@Column
private String value;

public void setKey(Key key) {
this.key = key;
}

public Key getKey() {
return key;
}

public void setContainer(Container container) {
this.container = container;
}

public Container getContainer() {
return container;
}

public void setValue(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return Item [key= + key + , value= + value + ];
}
}

@Service(TestLocalService)
public class LocalService {

protected final Log logger = LogFactory.getLog(getClass());

@Autowired
@Qualifier(jpaTemplate)
protected JpaTemplate jpaTemplate;

@Transactional(propagation = Propagation.REQUIRED)
public Key createContainer() {
Container container = new Container();
jpaTemplate.persist(container);
jpaTemplate.flush();
logger.fatal(new container + container.getKey());
return container.getKey();
}

@Transactional(propagation = Propagation.REQUIRED)
public Key generateItems(Key containerKey) {
Container container = jpaTemplate.find(Container.class,
containerKey);
Key key = null;
for (int i = 0; i  5; i++) {
Item item = new Item();
item.setContainer(container);
item.setValue(Integer.toString(i));
jpaTemplate.persist(item);
jpaTemplate.flush();
key = item.getKey();
logger.fatal(new item + item);
}
return key;
}

@Transactional(propagation = Propagation.REQUIRED)
public void changeItems(Key containerKey, Key itemKey) {
Container container = jpaTemplate.find(Container.class,
containerKey);
Item changedItem = jpaTemplate.find(Item.class, itemKey);
changedItem.setValue(xxx); //
---
PROBLEM HERE
jpaTemplate.flush();
logger.fatal(changed item:  + changedItem);
for (Item item : container.getItems()) {
logger.fatal(list item:  + item); //
 PROBLEM
HERE
}
}

public static void testListSync(LocalService service) {
// MAIN TEST
Key containerKey = service.createContainer();
Key itemKey = service.generateItems(containerKey);
service.changeItems(containerKey, itemKey);
}
}


EXECUTION LOG

### CALL createContainer
datastore_v3.BeginTransaction
datastore_v3.Put
datastore_v3.Commit

## LOG createContainer
SEVERE: new containerContainer(684)
27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService
generateItems

### CALL generateItems
datastore_v3.BeginTransaction
datastore_v3.Get
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Commit

### LOG generateItems
SEVERE: new itemItem [key=Container(684)/Item(685), value=0]
27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService

[appengine-java] JPA query contains stale data.

2010-03-29 Thread danblack
Hello.
I'm using JPA for the App Engine datastore.
And I've got some problems.

I've got an entity Container than contains entities Item(s).
Here is my actions.
I start transaction then update entity then flush updates to database.
Then I get all entities of class Item(s) for a container which
contains my updated Item.
But the list of retrieved items contains Item that does not have my
changes.
What is wrong with my code???


I've modelled this problem. (see code)

@Entity
public class Container implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;

@OneToMany(mappedBy = container, fetch = FetchType.LAZY)
private ListItem items = new ArrayListItem();

public void setKey(Key key) {
this.key = key;
}

public Key getKey() {
return key;
}

public void setItems(ListItem items) {
this.items = items;
}

public ListItem getItems() {
return items;
}

}

@Entity
public class Item implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;

@ManyToOne(fetch = FetchType.LAZY)
private Container container;

@Column
private String value;

public void setKey(Key key) {
this.key = key;
}

public Key getKey() {
return key;
}

public void setContainer(Container container) {
this.container = container;
}

public Container getContainer() {
return container;
}

public void setValue(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return Item [key= + key + , value= + value + ];
}
}

@Service(TestLocalService)
public class LocalService {

protected final Log logger = LogFactory.getLog(getClass());


public Key createContainer() {
em.getTransaction().begin();
Container container = new Container();
em.persist(container);
em.flush();
logger.fatal(new container + container.getKey());
em.getTransaction().commit();
return container.getKey();
}

public Key generateItems(Key containerKey) {
em.getTransaction().begin();
Container container = em.find(Container.class, containerKey);
Key key = null;
for (int i = 0; i  5; i++) {
Item item = new Item();
item.setContainer(container);
item.setValue(Integer.toString(i));
em.persist(item);
em.flush();
key = item.getKey();
logger.fatal(new item + item);
}
em.getTransaction().commit();
return key;
}

public void changeItems(Key containerKey, Key itemKey) {
em.getTransaction().begin();
Container container = em.find(Container.class, containerKey);
Item changedItem = em.find(Item.class, itemKey);
changedItem.setValue(xxx); // 
---
PROBLEM HERE
em.flush();
logger.fatal(changed item:  + changedItem);
for (Item item : container.getItems()) {
logger.fatal(list item:  + item); //
--- PROBLEM HERE (Item contains a
stale value of the field value)
}
em.getTransaction().commit();
}

public static void testListSync(LocalService service) {
// MAIN TEST
Key containerKey = service.createContainer();
Key itemKey = service.generateItems(containerKey);
service.changeItems(containerKey, itemKey);
}
}


EXECUTION LOG

### CALL createContainer
datastore_v3.BeginTransaction
datastore_v3.Put
datastore_v3.Commit

## LOG createContainer
SEVERE: new containerContainer(684)
27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService
generateItems

### CALL generateItems
datastore_v3.BeginTransaction
datastore_v3.Get
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Put
datastore_v3.Commit

### LOG generateItems
SEVERE: new itemItem [key=Container(684)/Item(685), value=0]
27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService
generateItems
SEVERE: new itemItem [key=Container(684)/Item(686), value=1]
27.03.2010 6:16:17