How to store changes to the database made using the inline editor from the

Hi, I am trying to get a basic Grid component to update Items kept in my database. I am missing an important clue here…

I create a Grid based on a List (using the BeanItemContainer(WithItems.class, theListFromTheDatabase))
The list is populated using an EntityManager (using the
LazyHibernateEntityManager
as suggested in the Vaadin book chapter 19). At that point the items are attached. Since the EntityManager gets evicted and a new one gets created I need to re-attach the items since changes will otherwise not get noticed and are not updated in the database.

What do I need to do: re-attach all items at the moment that LazyHibernateEntityManager receives a new instance? Or do I need to create wrapper objects for all the items and merge the item with the EntityManager myself? There does not seem to exist a mechanism to be informed about items being changed or did i miss that too?

I hope someone knows what is the way forward,
regards,
Jan.

When you want to save a detached object, you need to attach it first. Since you are using BeanItemContainer instead of JPAContainer, I’d recommend using EclipseLink as your JPA provider instead of Hibernate - personally, I’ve found it to work much better out-of-the box with Vaadin than Hibernate. For example, with EclipseLink, you don’t need to care about reattaching object manually, it just works.

Ok, i switched to org.eclipse.persistence:eclipselink (version 2.6.0) and got everything working similar to the Hibernate situation before.

But i don’t see a direct improvement over Hibernate: I think i still need to work with the LazyEntityManager pattern since the EntityManager is supposed to be designed for short-lived sessions.
As a result i still need to manually re-attach all items when a new instance of EntityManager is set?!
Or do i need to use the SessionManager/Session (org.eclipse.persistence.sessions) instead? I tried working with Session but do not get it to work (unwrap EntityManager to JpaEntityManger does give me the Session object but get errors running a query)…

Update: I found that I can set the EditorFieldGroup on a Grid:

Grid myGrid = …
FieldGroupFieldFactory myFieldFactory = …
BeanFieldGroup myBeanFieldGroup = new BeanFieldGroup(SomeItem.class);
myBeanFieldGroup.setFieldFactory(myFieldFactory)
myBeanFieldGroup.
addCommitHandler
(new FieldGroup.CommitHandler() {
public void preCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {

}
public void postCommit(FieldGroup.CommitEvent commitEvent) throws FieldGroup.CommitException {

}
}
myGrid.[b]
setEditorFieldGroup
/b;

This looks promising since I can merge my item in the postCommit but this does not work for some reason. The preCommit and postCommit are not invoked for some reason. Can this be a bug? Or is there a new way to do this?

Update: It is working: I needed to do: myGrid.getEditorFieldGroup().addCommitHandler(…) now I get notified when the Item is edited and saved using the inline editor of the grid!