Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / May 2005

Tip: Looking for answers? Try searching our database.

How implement this find method with bean inheritence?

Thread view: 
robertP - 06 May 2005 17:36 GMT
I have a ProductBean which is the super class of BookBean, ClothesBean
and I want to create a find method like:

[CODE]public ProductRemote findAllInCategory(Integer categoryID) throws
FinderException, RemoteException;[/CODE]

Since each bean is going to have its own table, what's the best way to
do this? Is this even possible with CMP find methods?
Big Jim - 07 May 2005 12:32 GMT
>I have a ProductBean which is the super class of BookBean, ClothesBean
> and I want to create a find method like:
[quoted text clipped - 4 lines]
> Since each bean is going to have its own table, what's the best way to
> do this? Is this even possible with CMP find methods?

Yes you can do it with cmp but I believe the current ejb spec does not allow
home interfaces to be inherited. Therefore you need to declare your
findAllInCategory() method in the interface in each bean. You can then
simply hard code the category id in the ejbql for each method in your
descriptors and simply call the method on the correct home interface runtime
type. (This is where a factory might come in useful to automatically get you
the correct type.)

The bean implementation and business methods can be inherited but the homes
currently must extend EJBHome or EJBLocalHome according to the spec, that's
what makes this tricky.
robertP - 07 May 2005 18:54 GMT
> You can then simply hard code the category id in the ejbql
> for each method in your descriptors

But I can't do that because if I have 2 different types of products
(say Books and Magazines) but they're both in the category "Print
Items," then I need to return two different Entity types. I know this
can be done in EJB 3.0, but how would I do it in 2.0?

Both entities will be stored in diff. tables from each other in the DB.
Obviously, I could do it in BMP, but I'd like to do it in CMP. Is there
a way to do it?
Big Jim - 07 May 2005 22:46 GMT
>> You can then simply hard code the category id in the ejbql
>> for each method in your descriptors
[quoted text clipped - 7 lines]
> Obviously, I could do it in BMP, but I'd like to do it in CMP. Is there
> a way to do it?

You could return a collection of print items in your printItems home, e.g.
with a query using "where categoryId IN(bookId, magazineId)". You would be
able to cast each item in the collection to printItem but not to book or
magazine.

I thnk the only way you can make this work sensibly is if your inheritance
tree follows you categorization i.e. you have books and magazines extending
printItems thus allowing you to group these items together.

If they are in separate tables i.e. not differentiated by an id column in
the same table, then they are different types of object and presumably have
different attribues/behaviour and I'm not then sure why you'd want to get
them by a category id, maybe you could look at your design and find a better
way to do this e.g. jst amalgamate the collections of each type in a wrapper
method to work with them from there.
You can have abstract schemas defined in your descriptor for a cmp bean that
extend over many tables but how this is done may well depend on your j2ee
server.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.