5

I am trying to store a Person object with ActiveAndroid. I set the birthdate like this: person.setBirthdate(new java.sql.Date((new Date()).getTime()));. After assigning all data i am calling person.save();.

I get a list of all persons from the database with this command: new Select().from(Person.class).execute();

If I do not close the app everything works fine (birthdate is always returned correctly from the database). However, when I close the app completely and then restart it, the birthdate is always null. All other fields (first name, last name etc.) are correct.

I really don't know why this is happening and would appreciate some help!

EDIT: After taking a closer look at my database I found out that the birthdate-column is not created. I am still not sure why the data is available when not closing the app though.

Second EDIT: I added a new column (a string) which is saved to the database and works just fine. So the problem is not an outdated database. All columns but the date column get created.

I also changed the date datatype to a string. The birthdate was then saved. Changing it back to a Date datatype resulted in the original problem again. Really weird... Does anyone know whats going on?

Liz_17
  • 51
  • 4
  • why u use java.sql.Date insteed java.util.Date? – LunaVulpo Mar 06 '17 at 13:00
  • did u solve the problem? – LunaVulpo Mar 06 '17 at 13:00
  • I was using JodaTime's `DateTime` as my column field type and it was silently not creating the column in the SQLIte database. You have to create a custom TypeSerializer if you're going to do this. See this for more info: https://github.com/pardom/ActiveAndroid/issues/516 – Joshua Pinter Mar 28 '17 at 22:33
  • @LunaVulpo Sorry I missed your comment. No, I unfortunately could not solve the problem back then :/ – Liz_17 Nov 22 '17 at 15:18

1 Answers1

3

It should be some caching problem. for saving Date try to use type serializer. it is so easy just read this page.

mehdi
  • 912
  • 7
  • 20
  • have you tried to update your schema or unistall and reinstalling your app again? – mehdi Sep 08 '15 at 15:06
  • I updated my schema (if that means increasing the database version number) and reinstalled the app, but still not working... – Liz_17 Sep 08 '15 at 16:35
  • You answer is not correct at all. Date is serialized by AA automatically according to https://github.com/codepath/android_guides/wiki/ActiveAndroid-Guide – nutella_eater Apr 25 '16 at 12:06