3 个等级:A、B、C。 B扩展了A,A有一个List,如何使它们在GAE Java中持久化
我的层次结构是:
Record 是一个超类,有很多扩展 Record 的类,比如 WellnessRecord。 还有一个类Note。记录拥有一个列表。
现在我想使用 GAE for Java 来 makePersistent(WellnessRecord),并在阅读 GAE 文档中有关拥有的一对多关系的内容后:http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html#Owned_One_to_Many_Relationships
我在注释中写了此内容.java:
@Persistent
private Record record //only for mapping to the owner class
Record.java 中的这个:
@Persistent(mappedBy = "record", defaultFetchGroup = "true")
@Element(dependent = "true")
protected LinkedList<Note> notes = new LinkedList<Note>();
但它没有按我的预期工作!
我可以通过向 WellnessRecord 的变量注释添加注释来 addNote(),并且 makePersistence(WellnessRecord)
我可以通过 getObjectById() 获取特定的 WellnessRecord 来编辑Note(),当我编辑注释时,GAE 将跟踪修改并自动保存。
但当我想deleteNote()时,总会有例外。
我调试了程序,发现从数据库中获取WellnessRecord并删除了Record
的notes
中的Note
,但是,修改保存到数据库时出现异常!
我跟踪执行情况,发现Note中的“record”变量即使已经makePersistent(),仍然为null。
在我的项目中,还有一个 Item 类,其中有 List,我类似地编写 @-annotations,但 addRecord()、editRecord()、deleteRecord() 进展顺利。所以问题应该是GAE对多态性的支持!
我对这个问题的假设是:当addNote()或editNote()时,我先找到Record,然后通过Record修改Note,因为Record可以很容易地找到Note,所以进展顺利。
但是当deleteNote()时,删除内存中的对象后,GAE跟踪修改并想要删除数据库中的Note,但由于Note的“记录”为空,所以无法通过Note找到Owner Record。
这就是我的详细问题。
总之:3个类:A、B和C。B扩展了A,A有一个List,如何使它们在GAE Java中持久化???
任何建议表示赞赏!
My hierarchy is:
Record is a super class, there are many classes that extends Record, say WellnessRecord.
There is another class Note. Record owns a List.
Now I want to makePersistent(WellnessRecord) using GAE for Java, and after reading this in GAE's document about Owned One-to-Many Relationships: http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html#Owned_One_to_Many_Relationships
I wrote this in Note.java:
@Persistent
private Record record //only for mapping to the owner class
and this in Record.java:
@Persistent(mappedBy = "record", defaultFetchGroup = "true")
@Element(dependent = "true")
protected LinkedList<Note> notes = new LinkedList<Note>();
But it doesn't work as I expected!
I can addNote() by adding a Note to WellnessRecord's variable notes, and makePersistence(WellnessRecord)
I can editNote() by get the particular WellnessRecord via getObjectById() and when I edit the notes, GAE will track the modification and save it automatically.
But when I want to deleteNote(), there would always be exceptions.
I debug the program and found that it went well in getting the WellnessRecord from database and delete the Note
in Record
's notes
, however, the exceptions came out when the modification is saved into the database!
I tracked the execution and found that the "record" variable in Note is still null even if it has been makePersistent().
In my project, there is also a Item class which has List, I write the @-annotations similarly, but addRecord(), editRecord(), deleteRecord() goes well. So the problem should be the GAE's support for polymorphism!
My hypothesis for the problem is that: When addNote() or editNote(), I find the Record first and modify Note via Record, since Record can easily find the Note, it goes well.
But when deleteNote(), after delete the object in memory, GAE tracks the modification and want to delete the Note in the database, but it couldn't find the Owner Record via Note since Note's "record" is null.
That's my problem in detail.
In a word: 3 classes: A,B, and C. B extends A, A has a List, how to make them persistent in GAE Java???
Any suggestions are appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论