Title: Nachricht
Hi Thorsten,
 
> either a cat or a dog. How can I get out of it?
 
Well :-) you simply won't get out of it with EJBs. They are simply not designed for true inheritance.
 
> But why is the ejb inheritance support in the new version if it makes no sense?
> Isn't it useful in some cases even it is not the pure object oriented design?
 
Richard implemented inheritance purely on the Java level. One bean inherits from another and aggregates all its superclass attributes into the same database table (Richard, is that correct?). It is just a shortcut to simplify programming a little.
 
OK, so I'd say: do not try to make inheritance REALLY work with EJBs. You'll spend about 6 months and end up with a very ugly solution. Use an O/R mapper and you'll be happier! :-)
 
Cheers...
Matthias
 
P.S.: Richard, how about using brute force and encoding the type of the subclass in the primary key of the entity? OH NO OH NO OH NO, HOHOHO! Matthias, stop fooling other people and go to bed! :-)
-----Original Message-----
From: Thorsten Lamby [mailto:[EMAIL PROTECTED]
Sent: Monday, December 08, 2003 9:36 PM
To: 'Matthias Bohlen'; [EMAIL PROTECTED]
Subject: RE: [Andromda-user] Next Release

Hi Matthias,
 
I guess you can read my mind. ;-)
That's what I though of, too: A person bean with a relationship to animals.
I think it would make sense, that a session bean can be used to get a collection of animal value objectss, which belong to a person and
this animals can be cats or dogs or both. Right? So the only thing you mean is, not to use the same inheritance structure for the bean classes!?
But why is the ejb inheritance support in the new version if it makes no sense?
Isn't it useful in some cases even it is not the pure object oriented design?
If I had no superclass, I cannot model the relationship between person and animal, can I? I think it is not a good solution to put a relationship
between person bean and dog bean AND between person bean and cat bean, especially thinking of a bean depending on an animal bean, say food bean,
which is eaten by one animal, so I would have two relationships (to cat and dog), but one food bean should only be eaten by one animal, which is
either a cat or a dog. How can I get out of it?
 
Cheers
Thorsten
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Matthias Bohlen
Sent: Saturday, December 06, 2003 9:25 AM
To: 'Thorsten Lamby'; [EMAIL PROTECTED]
Subject: RE: [Andromda-user] Next Release

Hi Thorsten,
 
making concrete inheritance work in EJB would mean to jump through all kinds of hoops - it's useless. Keep away from it, your code will look absolutely ugly! I prefer an O/R mapping tool like Hibernate that explicitly allows inheritance. The ejbHomeLocate() method makes the base class depend on the derived classes which violates central principles of object orientation.
 
Think of one more thing: Imagine a PersonBean that has a CMR collection of AnimalBeans. When you call PersonBean.getAnimals(), the EJB framework does not know which ones of the animals are cats and which ones are dogs. The EJB container will generate a select statement on the animal table only.
 
Inheritance with EJB sucks because they were not designed for it.
 
Cheers...
Matthias
-----Original Message-----
From: Thorsten Lamby [mailto:[EMAIL PROTECTED]
Sent: Friday, December 05, 2003 8:31 PM
To: 'Matthias Bohlen'; [EMAIL PROTECTED]
Subject: RE: [Andromda-user] Next Release

Hi Matthias,
 
that's right, but I can build an inheritance structure for the matching value objects, too.
An AnimalService session bean can coordinate the calls to the CatHome and the DogHome and return an AnimalValue
which means a DogValue object or a CatValue object. So the only problem is, that the inheritance structure is fixed in the
service class and I cannot easily extend it only by adjusting the AnimalService. To make it extensible one may use a kind
of server side factory pattern, so the AnimalService can load its concrete bean home classes from a config file. So this information
is very helpful for me.
 
Can you tell me, what happens in case of an EJB inheritance? Is it only an inheritance of the remote interfaces from eachother
(Cat extends Animal, Dog extends Animal) and the bean classes (DogBean and CatBean extend AnimalBean) or happens
something additionally?
 
Something to the point, that I cannot cast ... Is there really no possibility? Why can I not cast beans? Even not if I implement
the ejbLocateHome like this?
 
  public BaseCustomer ejbHomeLocate(String customerID) throws FinderException {
    //At this point, all base EJB classes must know their EJB subclasses...
    Context jndiCtx;
    BaseCustomerHome bHome;
    GoldCustomerHome gHome;
    PlatinumCustomerHome pHome;
    try {
      jndiCtx = new InitialContext();
      bHome = (BaseCustomerHome)ctx.getEJBLocalHome();
      gHome = (GoldCustomerHome)jndiCtx.lookup("GoldCustomerEJB");
      pHome = (PlatinumCustomerHome)jndiCtx.lookup("PlatinumCustomerEJB");
    } catch (NamingException e) {
      throw new FinderException("Cannot obtain JNDI initial context.");
    }
    BaseCustomer b=null;
    try {
      b = bHome.findByPrimaryKey(customerID);
      return b;
    } catch (FinderException e) {
    }
    try {
      b = gHome.findByPrimaryKey(customerID);
      return b;
    } catch (FinderException e) {
    }
    try {
      b = pHome.findByPrimaryKey(customerID);
      return b;
    } catch (FinderException e) {
    }
    throw new FinderException("Cannot find any bean with that key.");
  }
 
Bye and have a nice weekend
Thorsten
 
 
-----Original Message-----
From: Matthias Bohlen [mailto:[EMAIL PROTECTED]
Sent: Friday, December 05, 2003 11:01 AM
To: 'Thorsten Lamby'; [EMAIL PROTECTED]
Subject: RE: [Andromda-user] Next Release

Hi Thorsten,
 
next week, there will only be a maintenance release (2.1.1) that fixes the build.xml bug in the empty sample project wizard for Hibernate 2 projects. Support for abstract EJB inheritance is already in the code base of AndroMDA 3.x (see the HEAD branch in CVS). You may try it already if you do a CVS checkout and build AndroMDA from the sources which is only a matter of one line in a properties file and a call to "ant".
 
About EJB inheritance: There is no REAL inheritance in EJB. For example: Create three beans, call them AnimalBean, DogBean and CatBean. Let DogBean and CatBean inherit from AnimalBean. Let all the interfaces inherit, too. Then, call DogHome.create("fido") and CatHome.create("pussy"). Then, call AnimalHome.findByPrimaryKey("fido"). Surprise, surprise: You will get an AnimalBean, not a DogBean and you will NOT be able to cast. You see what happened?
 
So all that we do in the AndroMDA 3.x EJB cartridge is abstract inheritance. The base classes themselves cannot create instances and cannot find instances of derived classes.
 
Cheers...
Matthias
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Thorsten Lamby
Sent: Thursday, December 04, 2003 11:23 PM
To: [EMAIL PROTECTED]
Subject: [Andromda-user] Next Release

Hi Matthias,
 
you talked about a new release next week.
Is the support for EJB inheritance inside this release?
Someone told me you are working on this ...
For the value objects I adjusted the VSL file to solve this problem.
I think it is more difficult for the entity bean classes, because of the home interface, isn't it. In an article about this
inheritance problem I read that one have to implement ejbHomeLocate methods in the base bean class to reference
the subclass beans. Is that right?
 
Cheers
Thorsten
 
 

Reply via email to