Closed regocziTamas closed 2 years ago
I suggest taking a look at the ORMLite foreign collection example program.
The example has an "orders" ForeignCollection field in an "Account" class. The orders field is created when an Account is fetched from the database eg.
Account accountResult = accountDao.queryForId(account.getId());
The orders are persisted to a separate "orders" database table and the ForeignCollection field is populated using a simple query which selects orders by Account id.
It is possible to add items to a ForeignCollection field once it has been created by ORMLite and this is quite useful. However, the DAO getEmptyForeignCollection()
call you are making does not work the way you expect and is not causing the ForeignCollection field to be created.
Sorry for the slow response. You've prolly moved on by now. Your example worked for me. My only guess is that maybe getStaticWexDao()
wasn't returning the DAO you thought? Either that our maybe your table-config file had not been updated with the "exercises" field?
I am having the following code, I am trying to initialize the "exercises" ForeignCollection with the getEmptyForeignCollection() method before adding elements to it, but it keeps throwing an IllegalArgumentException, saying that "Could not find a field named exercises", when I call the method. It doesn't work when I remove the columnName attribute either. What am I doing wrong? Thank you for the answer in advance!