• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Views maps to business entities, good choice?

 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks in advance for your input,
Alfred
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic