我有非常简单的PersistenceCapable类:
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable
public class TheEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
public Long getId() {
return id;
}
@Persistent
private int version;
public int getVersion() {
return version;
}
public void setVersion(int version)
{
this.version=version;
}
}
我只是通过递增来更新版本(并且我添加了一些计算以使GAE热备新实例)
public void test2(){
PersistenceManager mgr = getPersistenceManager();
mgr.currentTransaction().begin();
TheEntity test = mgr.getObjectById(TheEntity.class, 5081359164899328L);
test.setVersion(test.getVersion()+1);
log.log(Level.SEVERE, "VERSION: " + test.getVersion());
for (int i = 0; i < 10000; i++)
{
long x = i*i;
x++;
}
mgr.currentTransaction().commit();
mgr.close();}
所以,我把代码调用了9次,但从未失败过。以下日志:
W1. I 02:28:21.331 2015-01-10 200 0 B 6839ms /_ah/warmup
1. I 02:28:38.407 2015-01-10 204 0 B 4343ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:28:38 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=4343 cpu_ms=2940 cpm_usd=0.000022 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
I 02:28:38.012 com.vaktu.MyEndpoint test2: VERSION: 1
2. I 02:28:42.493 2015-01-10 204 0 B 115ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:28:42 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=115 cpu_ms=70 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
I 02:28:42.444 com.vaktu.MyEndpoint test2: VERSION: 2
W2. I 02:28:42.495 2015-01-10 200 0 B 7061ms /_ah/warmup
3. I 02:28:54.196 2015-01-10 204 0 B 4647ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:28:54 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=4647 cpu_ms=3173 cpm_usd=0.000022 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
I 02:28:53.814 com.vaktu.MyEndpoint test2: VERSION: 3
4. I 02:28:59.126 2015-01-10 204 0 B 163ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:28:59 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=163 cpu_ms=70 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
I 02:28:59.036 com.vaktu.MyEndpoint test2: VERSION: 4
5. I 02:29:02.426 2015-01-10 204 0 B 119ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:29:02 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=119 cpu_ms=117 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
I 02:29:02.373 com.vaktu.MyEndpoint test2: VERSION: 5
6. I 02:29:06.947 2015-01-10 204 0 B 114ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:29:06 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=114 cpu_ms=70 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
I 02:29:06.896 com.vaktu.MyEndpoint test2: VERSION: 6
7. I 02:29:11.705 2015-01-10 204 0 B 101ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:29:11 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=101 cpu_ms=47 instance=00c61b117c31a94949f82af423e0f1a3c1ac35 app_engine_release=1.9.17
I 02:29:11.665 com.vaktu.MyEndpoint test2: VERSION: 7
8. I 02:29:30.133 2015-01-10 204 0 B 111ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:29:30 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=111 cpu_ms=117 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
I 02:29:30.085 com.vaktu.MyEndpoint test2: VERSION: 3
9. I 02:29:33.598 2015-01-10 204 0 B 158ms /_ah/spi/com.vaktu.MyEndpoint.test1
188.122.13.128 - - [09/Jan/2015:17:29:33 -0800] "POST /_ah/spi/com.vaktu.MyEndpoint.test1 HTTP/1.1" 204 0 - "Google-HTTP-Java-Client/1.18.0-rc (gzip)" "mmorpgmonsters.appspot.com" ms=158 cpu_ms=93 instance=00c61b117c4063829b2bf7ef35e1e6e8a0e41978 app_engine_release=1.9.17
I 02:29:33.509 com.vaktu.MyEndpoint test2: VERSION: 4
test1只调用test2,test2的代码在上面。 W1 =实例1的预热 W2 =实例2的预热 请求在实例1:1,2,8,9上运行 请求在实例2:3,4,5,6,7上运行 现在,经过9次更新后,应该将版本增加到9,我的数据库中的版本= 4。说真的,这对我来说是一场灾难......任何帮助都非常感激。如果有人实施了JPA并且可以测试它是否更好,请提供反馈。
我的jdoconfig.xml:
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
<property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.appengine.singletonPMFForName" value="true"/>
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
</properties>
</persistence-unit>
</persistence>
WEB-INF / lib中的JARS:
appengine-api-1.0-sdk-1.9.17.jar
appengine-api-labs.jar
appengine-api.jar
appengine-endpoints-deps.jar
appengine-endpoints.jar
appengine-jsr107cache-1.9.17.jar
asm-4.0.jar
datanucleus-api-jdo-3.1.3.jar
datanucleus-api-jpa-3.1.3.jar
datanucleus-appengine-2.1.2.jar
datanucleus-cache-3.1.3.jar //I want to use memcache after I finally make it work without it
datanucleus-core-3.1.3.jar
gcm-server.jar
geronimo-jpa_2.0_spec-1.0.jar
jdo-api-3.0.1.jar
json_simple-1.1.jar
jsr107cache-1.1.jar
jta-1.1.jar
我会非常,非常感谢你的帮助......