Nie można uzyskać identyfikatora nowo utworzonej trwałej jednostki JDO za pomocą wtyczki GAE / J DataNucleus wersja 2.1.2
Mój problem
Przenoszę moją aplikację z wersji 1.x do 2.0 wtyczki DataNucleus dla GAE / J przy użyciu nowego SDK 1.7.5 GAE / J. Zmienia to moją wersję JDO z 2.3 na 3.0.1. Moja trwała klasa encji ma klucz podstawowy typu zakodowanego łańcucha, a także dostęp tylko do odczytu do numerycznego identyfikatora obiektu. Każda instancja jest jedynym członkiem grupy podmiotów (dzieci i rodzice są połączeni tylko numerycznym identyfikatorem).
Wcześniej mogłem tworzyć i utrzymywać noweMyEntity
instancja, a następnie natychmiast uzyskać dostęp do jej identyfikatora numerycznego, aby zapisać go w rodzicuMyEntity
lista identyfikatorów podrzędnych instancji.
Teraz stwierdzam, że numeryczny identyfikator nowej instancji nie jest dostępny natychmiast po utrwaleniu - mimo że jest generowany i przechowywany i jest dostępny później.
Moje pytanie
Czy jest coś, co mogę zrobić, aby przywrócić dostęp do identyfikatora numerycznego bezpośrednio po utworzeniu i trwałości obiektu?
Ekstrakt konfiguracyjny „jdoconfig.xml”
<persistence-manager-factory name="big-table">
<property
name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"
/>
<property name="datanucleus.DetachAllOnCommit" value="true"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property
name="datanucleus.appengine.autoCreateDatastoreTxns"
value="true"
/>
[...]
</persistence-manager-factory>
Ekstrakt kodu trwałej klasy podmiotu
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class MyEntity implements Serializable
{
private static final long serialVersionUID = 1L;
// No setter for this read-only data member
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String sEncodedKey;
// No setter for this read-only data member
@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
private Long loID;
@Persistent
private Long loParentID;
//
// Other persistent data members
//
public Long getID()
{
return loID;
}
//
// Other getters and setters
//
}
Kod trwałości zawierający 3 punkty logowania
/**
* Create a new entity.
* @param loParentID
* The ID of the entity,
* a new child of which is to be created.
* @param sChildName
* The name of the new child to be created.
* @return
* The created entity child,
* or <code>null</code> if the operation was carried out unsuccessfully.
*/
public static MyEntity createEntityChild(Long loParentID, String sChildName)
{
MyEntity meResult = null;
MyEntity mePersistedChild = null;
PersistenceManagerFactory pmf =
DataExchange.getPersistenceManagerFactory(); // My own method
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
MyEntity meChild = new MyEntity();
meChild.setParentID(loParentID);
meChild.setName(sChildName);
meChild.setActive(true);
mePersistedChild = pm.makePersistent(meChild);
// "Touch" data member not in the default fetch group
ArrayList<Long> liChildIDs = mePersistedChild.getChildIDs();
if (liChildIDs != null)
liChildIDs.size();
if (mePersistedChild != null)
g_logger.log(Level.FINE, String.format(
"Pre-commit: mePersistedChild.getID() = %d,"
+ " mePersistedChild.getEncodedKey() = \"%s\".",
mePersistedChild.getID(), mePersistedChild.getEncodedKey()));
tx.commit();
if (mePersistedChild != null)
g_logger.log(Level.FINE, String.format(
"Post-commit: mePersistedChild.getID() = %d,"
+ " mePersistedChild.getEncodedKey() = \"%s\".",
mePersistedChild.getID(), mePersistedChild.getEncodedKey()));
}
finally
{
try
{
if (tx.isActive()) // Because of an exception, say
tx.rollback();
}
finally
{
pm.close();
}
}
if (mePersistedChild != null)
g_logger.log(Level.FINE, String.format(
"Post-pm-close: mePersistedChild.getID() = %d,"
+ " mePersistedChild.getEncodedKey() = \"%s\".",
mePersistedChild.getID(), mePersistedChild.getEncodedKey()));
[...]
return meResult;
}
Wyjście rejestrowania serwera Dev
24-Feb-2013 13:28:02 [...].MyEntityBusiness createMyEntityChild
FINE: Pre-commit: mePersistedChild.getID() = null, mePersistedChild.getEncodedKey() = "agttYXJrZXQtdHJlZXISCxIMSXRlbUNhdGVnb3J5GAUM".
24-Feb-2013 13:28:03 [...].MyEntityBusiness createMyEntityChild
FINE: Post-commit: mePersistedChild.getID() = null, mePersistedChild.getEncodedKey() = "agttYXJrZXQtdHJlZXISCxIMSXRlbUNhdGVnb3J5GAUM".
24-Feb-2013 13:28:03 [...].MyEntityBusiness createMyEntityChild
FINE: Post-pm-close: mePersistedChild.getID() = null, mePersistedChild.getEncodedKey() = "agttYXJrZXQtdHJlZXISCxIMSXRlbUNhdGVnb3J5GAUM".
24-Feb-2013 13:28:07 com.google.appengine.api.datastore.dev.LocalDatastoreService$PersistDatastore persist
INFO: Time to persist datastore: 141 ms
Weryfikacja wersji rozszerzenia JDO
Proces kompilacji powiódł się z fragmentem wyjściowym:
datanucleusenhancer:
09:33:00,531 (main) INFO [DataNucleus.Enhancer] - DataNucleus Enhancer for API "JDO"
09:33:01,125 (main) INFO [DataNucleus.Enhancer] - DataNucleus Enhancer (version 3.1.1) : Enhancement of classes
DataNucleus Enhancer (version 3.1.1) : Enhancement of classes
09:33:03,281 (main) INFO [DataNucleus.Enhancer] - Writing class file "[Path]\MyEntity.class" with enhanced definition
[... (N entries in all)]
09:33:04,046 (main) INFO [DataNucleus.Enhancer] - DataNucleus Enhancer completed with success for [N] classes. Timings : input=1922 ms, enhance=984 ms, total=2906 ms. Consult the log for full details
DataNucleus Enhancer completed with success for [N] classes. Timings : input=1922 ms, enhance=984 ms, total=2906 ms. Consult the log for full details
Środowisko oprogramowania
Serwer WWW: Google App Engine dla wersji Java 1.7.5Struktura sieci Web: Apache Wicket 6.5.0Wersja Java: 1.6.0_39; Java HotSpot (TM) Client VM 20.14-b01Wersja wtyczki GAE / J DataNucleus: 2.1.2Wersja DataNucleus Access Platform: 3.1.3Wersja JDO: 3.0.1System operacyjny: Microsoft Windows XP wersja 5.1 działająca na x86IDE: NetBeans 7.2 (kompilacja 201207171143)