Hibernate version:3.2.5 or newer
What is the best way of handling/convert pojo to view from the model?
I am not using spring/seam/ejb etc, just java with hibernate.
(Later on maybe we will convert this to use ejb3 instead.)
If I have for example a table named tabl1 with columns col1,col2,col3 mapped to tabl1.java pojo and wish to use this in the view part in a web or swing application for a TableComponent or a DropDownComponent.
where I would need specific properties for the TableComponent, like selectedrow, sortable, editable that is not stored in a db, just runtime properties that is used in the view.
I am using bean binding to get the properties in the pojo.
I am trying to do this using netbeans 6.1 witth jdk 6 and glassfish2.
I haven found any example that does not add the properties to the pojo/bean directly, but I am not sure this is the right way to go, since you are then messing with the model objects/pojos directly. The point of the mvc is that the model should stay the same regardless if it is a webb application or a swing application that use it, but it will need to be transformed/converted for the user interface.
Original pojo/bean
Code:
class tab1 {
public tab1(){
};
String col1;
String col2;
String col3;
}
Could I do something like this?
Code:
class tab1web extends tab1 {
public tab1web(){
super();
};
Boolean selectedrow;
Boolean sortable;
Boolean editable;
}
Or something like this
Code:
class tab1 {
public tab1(){
};
String col1;
String col2;
String col3;
// Not bound properties, only used in runtime
Boolean selectedrow;
Boolean sortable;
Boolean editable;
}
Or should it be done in another way ? Is there some other way to do it ?
Would one then create a new class that inherits from the base class, and include the extra properties ? Do you extend it using hibernate mappings or have to do this ?
Do you create a new class that include the extra properties along with the mapped ones in a table and use this ?
Would this class also have to be mapped using hibernate or can one accomplish this in another way, by only having the base class mapped ?
Any insight,ideas,recommendations would be greatly appreciated on how to do this the best/recommended way.
Since we want to try and keep the view model separated or as loosely coupled to the model as possible, yet handle this conversion/transformation efficiently.
This must be a fairly common problem to any developer trying to use hibernate in a web application or a swing application. However I haven't found any good solutions and examples on how you handle this the mvc way.
Any links to other forums or articles describing this would also be useful.
I have looked at all examples on netbeans and tried looking at the hibernate documentation and searched the web but not found the information i need.
/Kind Regards Roger