我有课要处理 PDF
@PersistenceCapable
public class GoogleDrivePDF {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String pdfName;
... geter, seter...
}
为了写入和读取数据,我这样做:
GoogleDrivePDF pdf = new GoogleDrivePDF();
key=KeyFactory.createKey(GoogleDrivePDF.class.getSimpleName(),"0B1IQEoiXFg3IWHhJNEtlMzlvQWs");
pdf.setKey(key);
pdf.setPdfName("NAME");
pm.makePersistent(pdf);
为了阅读:
pdf = pm.getObjectById(GoogleDrivePDF.class, "0B1IQEoiXFg3IWHhJNEtlMzlvQWs1");
一切正常!
现在我将创建一个:许多关系。
@PersistenceCapable
public class UsersPDFDocuments {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private List<GoogleDrivePDF> pdfs;
... seter, geter...
}
我写信给数据库:
List <GoogleDrivePDF> pdfFilesDao=...
GoogleDrivePDF pdf = new GoogleDrivePDF();
Key key= KeyFactory.createKey(GoogleDrivePDF.class.getSimpleName(), "0B1IQEoiXFg3IWHhJNEtlMzlvQWs1");
pdf.setKey(key);
pdf.setVerifyed(false);
pdf.setPdfName("mari123");
pdfFilesDao.add(pdf);
key= KeyFactory.createKey(UsersPDFDocuments.class.getSimpleName(), "mail@mail");
UsersPDFDocuments userData = new UsersPDFDocuments();
userData.setKey(key);
userData.setPdfs(pdfFilesDao);
pm.makePersistent(userData);
好的,一切正常! 但我现在无法阅读 PDF 数据!
我有错误:
HTTP ERROR 500
Problem accessing /test. Reason:
Could not retrieve entity of kind GoogleDrivePDF with key GoogleDrivePDF("0B1IQEoiXFg3IWHhJNEtlMzlvQWs1")
Caused by:
javax.jdo.JDOObjectNotFoundException: Could not retrieve entity of kind GoogleDrivePDF with key GoogleDrivePDF("0B1IQEoiXFg3IWHhJNEtlMzlvQWs1")
但我也这样做,就像我正在做的那样:
Key key = KeyFactory.createKey(GoogleDrivePDF.class.getSimpleName(), "0B1IQEoiXFg3IWHhJNEtlMzlvQWs1");
GoogleDrivePDF pdf = pm.getObjectById(GoogleDrivePDF.class, key);
当我测试时,为了获得值,我需要加密的密钥字符串。(见图) agtsdHYtY2hlY2tlcnJoCxIRVXNlcnNQREZEb2N1bWVudHMiIXZha2h0YW5nLmtvcm9naGxpc2h2aWxpQGdtYWlsLmNvbQwLEg5Hb29nbGVEcml2ZVBERiIcMEIxSVFFb2lYRmczSVdIaEpORXRsTXpsdlFXcww
当我添加 Unowned 时它起作用了!为什么?!
@Unowned
@Persistent
private List<GoogleDrivePDF> pdfs;