This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In a conversation about mapping data to objects, I was presenting the problem of displaying data saved in a database that I have. Once we start talking about retrieving data from a complex database schema, logical basic entities can't really hold the data in a good format.
To explain myself, I'll take the most common example. Tables: customer, order, order_details, product, vendor. Classes: Customer, Order, Product, Vendor.
Customer has a collection of Orders, Order has a collection of Products, Product has a Vendor Object and a Country Object (or just a string . Very simple basic and nice.
Now I want to display a list of product names and their vendors names for a certain customer. In the Database, it's simple, I'll create a view that inner joins customer to order, order to order_details, order_details to product, product to vendor, SELECT the names and uniqe identifiers and life is easy.
Now in the data tier I connect (JDBC) get a JdbcRowSetXImpl, and........ hmmmm now I don't want to send to the interface a typless result set to display, I want to put the data into a business entity that I can simply bind to a JSF data table. None of the business entities is suitable to create an object collection from and pass it to the interface...
One suggestion was to create a business entity to every view that I have in the DB, it's a big investement in the begining to make such a factory but then once done, adding to it is not going to be difficult. Also there are some software that would generate the entities automatically.
Is this a good approach? What's a better approach. Note that I want to be able to simply and directly bind the collection of entities to the data table directly to display it.