Please see the following code, the IllegalArgumentException should be
throwed but not.
// before calling this function, all File entities
// have already been created.
public void ImportData (DataInputStream dis) throws Exception {
// this is bug! This line should be put in the for loop.
// see below.
List entityList = new ArrayList ();
PersistenceManager pm = pmf.get().getPersistenceManager();
int numFiles = dis.readShort (); // about 20
for (int i = 0; i < numFiles; ++ i) {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// the beginning line should be here
//List entityList = new ArrayList ();
String filename = dis.readUTF ();
// ... more fields
Key fileKey = KeyFactory.createKey
(FileInfo.class.getSimpleName(), filename);
FileInfo fileInfo = pm.getObjectById(FileInfo.class, fileKey);
fileInfo.setFilename(filename);
// ... more fields
entityList.add (fileInfo);
int numRevisions = dis.readInt (); // about 5
for (int j = 0; j < numRevisions; ++ j) {
int revisionId = dis.readShort ();
// ... more fields
Key revisionKey = KeyFactory.createKey (fileKey,
FileRevision.class.getSimpleName(), revisionId);
FileRevision fileRevision = new FileRevision();
fileRevision.setId(revisionKey);
fileRevision.setRevisionId(revisionId);
// ... more fields
entityList.add (fileRevision);
}
// because the bug mentioned above, entityList.size ()
// will increase to about 100 in the end.
// The strange thing is the following calling will never
// throw Exceptions, although apparently
// there are many entity groups in the entityList.
pm.makePersistentAll (entityList);
// using makePersistent instead of makePersistentAll
// will also never throw Exceptions.
//for (Object entity : entityList) {
// pm.makePersistent (entity);
//}
tx.commit ();
} catch (Exception e) {
e.printStackTrace();
if (tx.isActive()) {
tx.rollback();
}
throw e;
} fanally {
pm.close ();
}
}
}
Original issue reported on code.google.com by Tapir....@gmail.com on 7 Jul 2010 at 2:23
Original issue reported on code.google.com by
Tapir....@gmail.com
on 7 Jul 2010 at 2:23