我根据以下实体创建了数据库:
Entity image = schema.addEntity("Image");
image.setTableName("Images");
image.addStringProperty("id").primaryKey();
image.addStringProperty("size128");
image.addStringProperty("size320");
Entity user = schema.addEntity("User");
user.setTableName("Users");
user.addStringProperty("id").primaryKey();
user.addStringProperty("fullName");
Property userImageIdProperty = user.addStringProperty("imageId").getProperty();
user.addToOne(image, userImageIdProperty);
当我尝试添加新用户时,图像不会被存储。
Image image = new Image();
User player = new User();
player.setId(advisorClient.getId());
player.setFullName(advisorClient.getFullName());
if (advisorClient.getAvatar() != null) {
image.setId(advisorClient.getAvatar().getId());
image.setSize128(advisorClient.getAvatar().getW128());
image.setSize320(advisorClient.getAvatar().getW320());
player.setImage(image);
}
daoSession.getUserDao().insertOrReplace(user);
我以错误的方式存储它?
答案 0 :(得分:0)
您必须像对待用户一样在数据库中插入图像。
Image image = new Image();
User player = new User();
player.setId(advisorClient.getId());
player.setFullName(advisorClient.getFullName());
if (advisorClient.getAvatar() != null) {
image.setId(advisorClient.getAvatar().getId());
image.setSize128(advisorClient.getAvatar().getW128());
image.setSize320(advisorClient.getAvatar().getW320());
player.setImage(image);
daoSession.getImageDao().insertOrReplace(image);
}
daoSession.getUserDao().insertOrReplace(user);