[LazyQueryContainer] How to add data to existing EntityContainer

Hi Folks,

I’m using EntityContainer from LazyQueryContainer 1.2.9 as a data source for a Table. I need to figure out how to add a new data object to an existing EntityContainer.

I’m able to build an EntityContainer and have it provide data to the Table just fine. How do I add a new object to the EntityContainer without destroying and rebuilding it?

Here’s the basic code:


// Create Hibernate EntityManager()
EntityManager em = RequestHandler.createEntityManager();

container = new EntityContainer<Person>(em, 
		true, 			// True if application manages transactions instead of container.
		false, 			// True if entities are detached from PersistenceContext.
		true, 			// True if items are wrapped to CompositeItems.
		Person.class,		// The person class.
		getRowsPerPage() * 2, 	// The batch size.
		new Object[] { ID_DBID }, // Properties participating in the native sort.
                new boolean[] { true });
 setContainerDataSource(container);

After this code is run the user fills out a Form to create a new Person and that object is saved to the datastore using a different EntityManager(). I use a different EntityManager() because LQC uses EntityManager even after the request is finished while my code in general uses a pattern of creating one EntityManager() at the start of the request and committing/closing it at the end of the request.

So how do I tell EntityContainer about the newly saved Person object?

I’ve tried a container.refresh() but that reloads only the same objects originally loaded and does not include the newly saved Person object. I presume this is because the EntityManager doesn’t know about the newly saved Person.

Thanks in advance.

mike