简体   繁体   中英

ORMLite initialize foreign collection

I have foreign collection field on my Object. If I create Object > save it > query for it : then I have it and can use it. But if I create Object and try to access foreign collection field right away then it's null. How can I initialize it?

As part of the ORMLite Dao class, there is an assignEmptyForeignCollection(...) method . This creates an empty collection for you and assigns it to the proper field.

To quote from the Javadocs for the method :

Creates an empty collection and assigns it to the appropriate field in the parent object. This allows you to add things to the collection from the start. For example let's say you have an Account which has the field:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM