views:

45

answers:

1

Our project is an Eclipse RCP application using Hibernate as an ORM. I recently learned about JFace databinding, in which the GUI and data models can be synchronized automagically.

I put together a short test implementation along the lines of Lars Vogel's excellent JFace Data Binding Tutorial and was fairly impressed with the framework.

Is there any way, then, to hook this into Hibernate, such that changes made in an observed widget are automatically persisted in the database? This seems like a natural thing to want to do, and yet I've found no good tutorials.

I suspect that I may be barking up the wrong tree, or have missed some fundamental concept.

Has anyone tried to do this? What's the "best practice" here?

+1  A: 

I do not think you should persist your data model to a database after every modification in the GUI. Some reasons:

  • it could lead to really bad performance (the worst case is calling a database update after every keystoke)
  • it could be hard to implement some GUI behaviour (e.g. can your user 'cancel' an edit operation? How do you 'restore' the original values?)

If your application form contains some kind of an Apply/Save/etc. button and a Cancel button you have some well defined points where you need to do database operations:

  • use data binding to connect your data model and the GUI
  • an Apply or Save button handler persists the edited entity in the database
  • a Cancel button handler could reload the edited entity from the database if necessary (discarding the edits)

Just my two cents...

Disclaimer: I used very simple examples above to illustrate my thoughts. E.g. you should never call database/Hibernate operations directly from the GUI (use a 'middle tier' between the GUI and the database to ensure modularity and testability).

Csaba_H