Persisting model classes with JavaFX properties using hibernate is not impossible but requires some efforts. You can either use the "property access" (as described here) or map and bind all JavaFX fields to good old java fields. Both approaches have major drawbacks. Persisting JavaFX collections is almost impossible with the first approach and the second approach involve writing a lot a boiler code and to register tons of listeners to maintain the state between the JavaFX fields and their corresponding Java fields.
We recently decided to test a new persistence solution: Java Content Repository and especially the ModeShape implementation. Java Content Repository are designed to store content and metadata about this content. It looks like they are a good solution to persist application data, especially if you are manipulating lot of files and binary data.
The tree structure of a Java Content Repository allow a pretty simple mapping of graphs of Java objects. Mapping can be done either manually or using an object mapping framework. It looks like that one of the most used JCR mapping framework is JCROM. JCROM is described as a lightweight framework for mapping Java objects to/from a Java Content Repository (JCR).
JCROM was initially designed to handle most basic Java types but it was in 2008 when JavaFX did not exist! So we forked this excellent project and tried to extend it to support JavaFX properties...and it turned out to be pretty easy, even for JavaFX collections.
So we are pleased to announce that you can use JCROMfx to map your Java objects with JavaFX properties directly to/from a JCR repository! Just annotate your JavaFX properties and you are ready to persist them. This include all basic JavaFX properties (StringProperty, IntegerProperty,...), collections (ListProperty, MapProperty) and object properties of enum or of other objects (using @JcrChildNode)
Just to give you an overview of how a bean looks like with JCROM annotation & JavaFX properties :
Feedback is welcome :)
Aucun commentaire:
Enregistrer un commentaire