Singleton JPAContainer?

Hello,

I’m new to JPAContainer, my question is “Should I keep one instance of JPAContainer for an entity class across application, or make a new one every time I need it. Or does it make any difference?”

If my page for listing entities and adding an entity are on two different pages (I’m using navigator 7), should I somehow pass the container instance from the listing page to the adding page?

I can’t answer for the JPA part, but you need to be careful with singletons see
this chapter of the book

You should use separate JPAContainer instances, but if their lifetimes are the same (e.g. the lifetime of the whole session, or in the same view), they can probably share an entity provider instance.

Thanks a lot for the reply.

So if I have two tabs, one for listing objects and one for adding. Each page has separate container instance. And I want to achieve that when a new one is added, the list will auto refresh.

My guess is I should keep a global list of initialized container instances and call refresh() when they need to be synced?

Maybe remove a instance from the global list in individual view’s detach() function?

If two JPAContainers share an entity provider, they listen to notifications from it and thus all of them are updated when e.g. adding an item to one of them.
These listeners are also the reason why you might not want to share entity providers if the lifetimes of the containers are very different (e.g. new instances of one are created frequently while the other one is kept the whole lifetime of a session, leading to container instances and their listeners being kept in memory unnecessarily if not explicitly detached from the entity provider).