I am using greendao for an application of mine. I used a generator to create all of the tables and I am running test right now. The insert is working for the user table, but not for the group table. There's little different between the two entity models, so I don't know why I'm getting an insert error.
Here are all of my models
private static void addMessage() {
Entity message = schema.addEntity("Message");
message.addIdProperty().autoincrement();
message.addStringProperty("mtext").notNull();
message.addDateProperty("date").getProperty();
message.addLongProperty("userId").notNull();
message.addLongProperty("groupId").notNull();
}
private static void addUser(){
Entity user = schema.addEntity("User");
user.addIdProperty().autoincrement();
user.addStringProperty("username").notNull().unique();
user.addStringProperty("email").notNull().unique();
// Not necessary if group does not exist
user.addStringProperty("token").unique(); // Doesn't have to be there unique
}
private static void addGroup(){
Entity group = schema.addEntity("Group");
group.addIdProperty().autoincrement();
group.addStringProperty("name").notNull();
group.addStringProperty("description").notNull();
}
private static void addUserToGroup(){
Entity ugSchema = schema.addEntity("UserGroup");
ugSchema.addIdProperty().autoincrement();
ugSchema.addLongProperty("userId").notNull();
ugSchema.addLongProperty("groupId").notNull();
}
Here's my test method. Keep in mind that I use statics to control the DAO sessions. If you think that might contribute to something tell me.
public void testDB(){
User inUser = new User();
inUser.setEmail("KevinKivo@gmail.com");
inUser.setUsername("KevinKivo");
inUser.setToken("TheRandomTokenGoesHere");
Database.getuser().insert(inUser);
ArrayList<User> user = (ArrayList<User>)
Database.getuser()
.queryBuilder()
.list();
// Can create message and
for(User us: user){
Log.i(TAG, "Email: " + us.getEmail());
Log.i(TAG, "Username: " + us.getUsername());
Log.i(TAG, "Token: " + us.getToken());
}
// Create a group here
Group sampleGroup = new Group();
sampleGroup.setName("SampleName");
sampleGroup.setDescription("SampleDescription");
Log.i(TAG, "" + Database.getGroup());
Log.i(TAG, "" + Database.getuser());
Log.i(TAG, "" + Database.getGroup().insertOrReplace(sampleGroup));
// Add user and group id relation here
}
Inserting the user works perfectly while inserting a group does not. Could somebody explain why? This issue is plaguing my life right now. I'm working on other parts of the application, but this is seriously important.