我上课要学习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");
一切正常!
现在我将创建 One:Many realationship。
@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);
当我测试时,为了得到这个值,我需要一个enycrypted String of key。 (见图)agtsdHYtY2hlY2tlcnJoCxIRVXNlcnNQREZEb2N1bWVudHMiIXZha2h0YW5nLmtvcm9naGxpc2h2aWxpQGdtYWlsLmNvbQwLEg5Hb29nbGVEcml2ZVBERiIcMEIxSVFFb2lYRmczSVdIaEpORXRsTXpsdlFXcww
当我添加Unowned时,它有效!为什么?!
@Unowned
@Persistent
private List<GoogleDrivePDF> pdfs;