This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
I would like to have your opinion on the best way of managing the inheritance and the polymorphism. I develop with JSF and EJB3. I have an application allowing to manage articles (books or CD). I have a class mother Article and two class girls book and CD. I have a business layer with the method addArticle(Article article). So I can use CD objet or Book objet as argument.
First question : Must i have to create a page to add a book and a page to add a CD ? How can i use a single page ?
I also wish, to have a page allowing to list all the articles, or all the books or every CD.
To list all the articles, no pb, I have a method listArticles (); With the following request: em.createQuery (" SELECT has Article has ") .getResultList ();
Question 2 : To have only books or CD-ROM, Must I have two other methods listCD with em.createQuery (" SELECT d from disk d ") .getResultList (); and listCd() with em.createQuery (" CD-ROM SELECT c from c ") .getResultList ();? Or may I use only my method listerArticles () and then make a filter at the level of my page JSF?
Thanks and sorry for my poor English ;)
Joined: Aug 15, 2004
Regarding your first question. I would say its reasonable to have a single page and decide whether to show book specific fields or CD specific using a parameter.
Now for your second question. I would say its not at all a good idea to get the complete list from DB and filter it out using your code. The idea is why select all when you already know that you are going to remove half - or say few - based on a specific filter. The better would be something like this,