I have multiple tables with a lot of data in it. I’m only mentioning things pertinent to the question. For rendering data on the jsp, I only need selective data from different tables.
In reference to travel-vacation, lets say I have to retrieve and render holiday package name, itinerary duration and total price per defaults.
- Holiday package name is in table
HolidayPackage(id, name) - Itinerary duration in table Itinerary
Itinerary(idPkg, idItinerary, dayNum) = (SUM aggregate of itinerary rows for a given package ) - Price is defined in two different tables base price and total price
= (Sum( base(idPkg) + total(idPkg) ))
How can I retrieve selective data from these database tables to render the name, itinerary duration and total price for a given holiday package ?
I am using Hibernate with mysql as my database.
Thoughts:
Can I use a view to fetch data into my custom java object Result where Result is defined as:
class Result{
String name;
Intger itineraryDuration;
BigDecimal totalPrice;
}
Also, can I use functions as the definition of column values in views ?
What I do with views is I create an immutable hibernate model class and associated DAO to query the model class.
I annotate the model class as follows:
I also set the setters to protected, but this is optional.
If the view is structured similar to an existing model class, you can use a named query and map it to your model using the resultClass attribute. The following is for Oracle so if using anything else, the query parameter would be different.
In hibernate, you can use functions as follows: