我一直在尝试使用 GreenDAO 创建数据库模型。当我尝试在不同表之间创建多个关系时,问题就开始了。
基本上,我有一个Message
桌子,一个Conversation
表和一个User
table.
用户有一个消息列表,并且该消息有一个父对话。
我尝试编写以下代码来创建数据库:
private static void addUser(Schema schema) {
user = schema.addEntity("User");
userId = user.addIdProperty().getProperty();
user.addStringProperty("facebookId").unique().index();
user.addStringProperty("firstName");
user.addStringProperty("lastName");
user.addStringProperty("fullName");
user.addStringProperty("photoUrl");
}
private static void addMessage(Schema schema) {
message = schema.addEntity("Message");
messageId = message.addIdProperty().getProperty();
message.addStringProperty("messageId").primaryKey();
message.addDateProperty("date");
message.addStringProperty("content");
message.addStringProperty("typeString");
}
private static void addConversation(Schema schema) {
conversation = schema.addEntity("Conversation");
conversation.addIdProperty();
conversation.addStringProperty("conversationId");
// REST OF THE CODE
}
private static void fakeRelationship(Schema schema) {
Property author = message.addLongProperty("author").getProperty();
Property parent = message.addLongProperty("parent").getProperty();
message.addToOne(user, author);
message.addToOne(conversation, parent);
user.addToMany(message, author);
conversation.addToMany(message, parent);
}
运行此代码后,我收到此错误:
Exception in thread "main" java.lang.RuntimeException: Currently only single FK columns are supported: ToOne 'parent' from Message to Conversation
at de.greenrobot.daogenerator.ToOne.init3ndPass(ToOne.java:91)
at de.greenrobot.daogenerator.Entity.init3rdPassRelations(Entity.java:557)
at de.greenrobot.daogenerator.Entity.init3ndPass(Entity.java:550)
at de.greenrobot.daogenerator.Schema.init3ndPass(Schema.java:185)
at de.greenrobot.daogenerator.DaoGenerator.generateAll(DaoGenerator.java:94)
at de.greenrobot.daogenerator.DaoGenerator.generateAll(DaoGenerator.java:79)
at com.glidetalk.dao.generator.GlideDaoGenerator.main(GlideDaoGenerator.java:27)
这实际上意味着我无法为数据库中的每个表创建多个关系吗?!
我必须手动编写所有内容吗?
greenDAO 支持您尝试做的事情,并且您的代码看起来也不错。我将其复制到我的工作区中,并且执行得非常好。所以我猜你遗漏的代码有问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)