Re: [JBoss-user] Help! - Can EJB inherit from normal classes? Packaging with normal classes?
The EJB inheritance question crops up periodically in different guises and forums. A good discussion is at: http://www.theserverside.com/discussion/thread.jsp?thread_id=265 There are lots of gotchas, e.g. narrowing an inherited remote. And even if the technical problems are overcome, the implicit data model lock-in will often break as the system evolves. I've reluctantly experimented with different flavors of EJB inheritance from time to time. I always come to the same conclusion: the only situation where inheritance is practical is an abstract non-distributed superclass of Entity Bean implementations for simple housekeeping functionality, and then sparingly. J2EE is complicated enough without the inheritance contortion. Even with expensive OR mapping tools, at least as of the last time I used one in 2000. I find it occasionally useful to inherit data object classes. E.g.: CustomerBean { String name; CustomerData data; ... } EmployeeBean { String name; EmployeeData data; ... } PersonData { String name; ... } CustomerData extends PersonData { ... EmployeeData extends PersonData { ... But even here a better solution is to use role aggregates: abstract PersonRole { PersonData person; } CustomerData extends PersonRole { ... EmployeeData extends PersonRole { ... A useful design check is: Could somebody who cares less about OO purity or system integrity break this design? Because that Somebody always seems to surface the week after go-live. -- Fred Loney Enterprise Java Consultant Spirited Software, Inc. [EMAIL PROTECTED] ZHU Jia wrote: > Many thanks for the detailed information! > But I've some questions here: > 1. I thought reflection is forbidden by the EJB spec, have you used it > successfully in your code? > 2. As far as I see, the way you do it is delegation and not inheritence, > and you don't make this for conversion of individual Java class to EJB > but as a general solution, right? So what's your experience with it > performance-wise? And would it always work? > > Many thanks in advance! > > regards > ZHU Jia > > "Schouten, Andreas" schrieb: > > > > Hello Jia! > > > > We migated the folowd situation to ejb > > > > Class ImplBasic implements InterfaceA > > > > Class Impl1 extendes ImplBasic > > Class Impl2 extendes ImplBasic > > Class Impl3 extendes ImplBasic > > ... > > > > InterfaceA obj = (Inter...)new Implx(...) > > > > as > > > > MyRemote extends InterfaceA, EJBObject > > > > MyBean extends SessionBean { > > private InterfaceA delegate; > > > > ejbCreate(String implementationClass){ > > delegate = (InterfaceA) > > ImplBasic.getInstanceOf(implementationClass); > > > > aInterfaceMethod(...) { > > delegate.aInterfaceMethod(); > > } > > > > where getInstaceOf creates a instance of the implementation class via > > reflection. > > > > Thats the only way I saw to implement a remote interface with many > > implementations. Maybe there is a better way? > > > > Andreas > > > > > -Original Message- > > > From: ZHU Jia [SMTP:[EMAIL PROTECTED]] > > > Sent: 03 July 2001 07:28 > > > To: EJBList; [EMAIL PROTECTED] > > > Cc: jboss-user > > > Subject: [JBoss-user] Help! - Can EJB inherit from normal classes? > > > Packaging with normal classes? > > > > > > Hello, > > > > > > I've a question on inheritence in EJB. > > > As I'm working on the adaption of an existing Java framework, I have to > > > convert many normal Java classes to EJB. But I'm not sure what to do with > > > the inheritence. Someone in the list suggested I let the RemoteInterface > > > inherit from some super interface and let the BeanClass inherit from the > > > super implementation. This way, if a type of the super interface is > > > expected, then an EJB RemoteInterface can be returned, which looks quite > > > reasonable to me, so I was trying to do just that. > > > But the problem is, I didn't seem to be able to compile because I cann't > > > have any constructor in the BeanClass (O'Reilly book), which I do have in > > > the original class that the bean should substitute:-( > > > I know, normlly the stuff in the constructor is done in the ejbCreate, but > > > in my case, I have invokation of super() in the constructor, which is of > > > course bad for EJB. But it didn't work even if I don't use the super() but > > > move the init code from super class to the b
RE: [JBoss-user] Help! - Can EJB inherit from normal classes? Packaging with normal classes?
The bean just calls a static method which return an object. I can't see a difference for the bean about the way this class instantiate the object (reflection or not). But I'm not shure about the spec here. It's claer, that it is forbidden to create a bean itself via reflection. This is the responsebility of the container. I use delegation and not inheritance because I don't want declare many beans with th same interface in the deployment descriptor. (And don't see a other way assigning a remote inteface to different implementations.) It works for us without problems. Of cause You can inherit Your beans and bean interfaces from other classes. Examle: public interface ListableHome extends EJBHome { java.util.Collection findByGroup(String groupId) throws FinderException, RemoteException; } were ListableHome is superclass for some home interfaces and public interface Listable extends EJBObject { String getTitle() throws RemoteException; String getId() throws RemoteException; } is superclass for the corresponding bean class Now You can create a list of beans (i.e. a html select) without knowin the beanclass in the code: ListableHome lh = (ListableHome)initial.lookup(entity); Collection lset = lh.findByGroup(type); Iterator it = lset.iterator(); Listable le; while (it.hasNext()) { le=(Listable)it.next(); title=le.getTitle(); id=le.getId(); } > -Original Message- > From: ZHU Jia [SMTP:[EMAIL PROTECTED]] > Sent: 04 July 2001 09:15 > To: [EMAIL PROTECTED] > Subject: Re: [JBoss-user] Help! - Can EJB inherit from normal > classes? Packaging with normal classes? > > Many thanks for the detailed information! > But I've some questions here: > 1. I thought reflection is forbidden by the EJB spec, have you used it > successfully in your code? > 2. As far as I see, the way you do it is delegation and not inheritence, > and you don't make this for conversion of individual Java class to EJB > but as a general solution, right? So what's your experience with it > performance-wise? And would it always work? > > Many thanks in advance! > > regards > ZHU Jia > > "Schouten, Andreas" schrieb: > > > > Hello Jia! > > > > We migated the folowd situation to ejb > > > > Class ImplBasic implements InterfaceA > > > > Class Impl1 extendes ImplBasic > > Class Impl2 extendes ImplBasic > > Class Impl3 extendes ImplBasic > > ... > > > > InterfaceA obj = (Inter...)new Implx(...) > > > > as > > > > MyRemote extends InterfaceA, EJBObject > > > > MyBean extends SessionBean { > > private InterfaceA delegate; > > > > ejbCreate(String implementationClass){ > > delegate = (InterfaceA) > > ImplBasic.getInstanceOf(implementationClass); > > > > aInterfaceMethod(...) { > > delegate.aInterfaceMethod(); > > } > > > > where getInstaceOf creates a instance of the implementation class via > > reflection. > > > > Thats the only way I saw to implement a remote interface with many > > implementations. Maybe there is a better way? > > > > Andreas > > > > > -Original Message- > > > From: ZHU Jia [SMTP:[EMAIL PROTECTED]] > > > Sent: 03 July 2001 07:28 > > > To: EJBList; [EMAIL PROTECTED] > > > Cc: jboss-user > > > Subject: [JBoss-user] Help! - Can EJB inherit from normal > classes? > > > Packaging with normal classes? > > > > > > Hello, > > > > > > I've a question on inheritence in EJB. > > > As I'm working on the adaption of an existing Java framework, I have > to > > > convert many normal Java classes to EJB. But I'm not sure what to do > with > > > the inheritence. Someone in the list suggested I let the > RemoteInterface > > > inherit from some super interface and let the BeanClass inherit from > the > > > super implementation. This way, if a type of the super interface is > > > expected, then an EJB RemoteInterface can be returned, which looks > quite > > > reasonable to me, so I was trying to do just that. > > > But the problem is, I didn't seem to be able to compile because I > cann't > > > have any constructor in the BeanClass (O'Reilly book), which I do have > in > > > the original class that the bean should substitute:-( > > > I know, normlly the stuff in the constructor is done in the ejbCreate, > but > > > in my case, I have invokation of super() in the constructor, which is
Re: [JBoss-user] Help! - Can EJB inherit from normal classes? Packaging with normal classes?
Many thanks for the detailed information! But I've some questions here: 1. I thought reflection is forbidden by the EJB spec, have you used it successfully in your code? 2. As far as I see, the way you do it is delegation and not inheritence, and you don't make this for conversion of individual Java class to EJB but as a general solution, right? So what's your experience with it performance-wise? And would it always work? Many thanks in advance! regards ZHU Jia "Schouten, Andreas" schrieb: > > Hello Jia! > > We migated the folowd situation to ejb > > Class ImplBasic implements InterfaceA > > Class Impl1 extendes ImplBasic > Class Impl2 extendes ImplBasic > Class Impl3 extendes ImplBasic > ... > > InterfaceA obj = (Inter...)new Implx(...) > > as > > MyRemote extends InterfaceA, EJBObject > > MyBean extends SessionBean { > private InterfaceA delegate; > > ejbCreate(String implementationClass){ > delegate = (InterfaceA) > ImplBasic.getInstanceOf(implementationClass); > > aInterfaceMethod(...) { > delegate.aInterfaceMethod(); > } > > where getInstaceOf creates a instance of the implementation class via > reflection. > > Thats the only way I saw to implement a remote interface with many > implementations. Maybe there is a better way? > > Andreas > > > -Original Message- > > From: ZHU Jia [SMTP:[EMAIL PROTECTED]] > > Sent: 03 July 2001 07:28 > > To: EJBList; [EMAIL PROTECTED] > > Cc: jboss-user > > Subject: [JBoss-user] Help! - Can EJB inherit from normal classes? > > Packaging with normal classes? > > > > Hello, > > > > I've a question on inheritence in EJB. > > As I'm working on the adaption of an existing Java framework, I have to > > convert many normal Java classes to EJB. But I'm not sure what to do with > > the inheritence. Someone in the list suggested I let the RemoteInterface > > inherit from some super interface and let the BeanClass inherit from the > > super implementation. This way, if a type of the super interface is > > expected, then an EJB RemoteInterface can be returned, which looks quite > > reasonable to me, so I was trying to do just that. > > But the problem is, I didn't seem to be able to compile because I cann't > > have any constructor in the BeanClass (O'Reilly book), which I do have in > > the original class that the bean should substitute:-( > > I know, normlly the stuff in the constructor is done in the ejbCreate, but > > in my case, I have invokation of super() in the constructor, which is of > > course bad for EJB. But it didn't work even if I don't use the super() but > > move the init code from super class to the bean, compiler simply says it > > cann't deal with the constructor in the super class:-( > > Now I'm wondering, is it that I've done something wrong or is such thing > > not > > possible by definition? Anyone with experience here, comments are heartily > > welcome! > > Also, another question would be: If the purpose of an EJB is to substitute > > some normal class, should I put it in it's own package, or should I leave > > it > > in the original package? If I put it in a new package, then many > > "protected" > > access modifier has to be "cracked open" to "public" in the original > > package, which seems hairy to me. But I don't know whether it's > > possible/feasible to package EJBs with the normal classes and make them > > one > > big jar, will the app server have any problem with it? > > The problems are quite urgent and I'm looking forward to your reply! > > Many thanks in advance! > > > > regards > > ZHU Jia > > > > > > ___ > > JBoss-user mailing list > > [EMAIL PROTECTED] > > http://lists.sourceforge.net/lists/listinfo/jboss-user > > If you have received this e-mail in error or wish to read our e-mail disclaimer >statement and monitoring policy, please refer to > http://www.drkw.com/disc/email/ or contact the sender. > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] Help! - Can EJB inherit from normal classes? Packaging with normal classes?
Hello Jia! We migated the folowd situation to ejb Class ImplBasic implements InterfaceA Class Impl1 extendes ImplBasic Class Impl2 extendes ImplBasic Class Impl3 extendes ImplBasic ... InterfaceA obj = (Inter...)new Implx(...) as MyRemote extends InterfaceA, EJBObject MyBean extends SessionBean { private InterfaceA delegate; ejbCreate(String implementationClass){ delegate = (InterfaceA) ImplBasic.getInstanceOf(implementationClass); aInterfaceMethod(...) { delegate.aInterfaceMethod(); } where getInstaceOf creates a instance of the implementation class via reflection. Thats the only way I saw to implement a remote interface with many implementations. Maybe there is a better way? Andreas > -Original Message- > From: ZHU Jia [SMTP:[EMAIL PROTECTED]] > Sent: 03 July 2001 07:28 > To: EJBList; [EMAIL PROTECTED] > Cc: jboss-user > Subject: [JBoss-user] Help! - Can EJB inherit from normal classes? > Packaging with normal classes? > > Hello, > > I've a question on inheritence in EJB. > As I'm working on the adaption of an existing Java framework, I have to > convert many normal Java classes to EJB. But I'm not sure what to do with > the inheritence. Someone in the list suggested I let the RemoteInterface > inherit from some super interface and let the BeanClass inherit from the > super implementation. This way, if a type of the super interface is > expected, then an EJB RemoteInterface can be returned, which looks quite > reasonable to me, so I was trying to do just that. > But the problem is, I didn't seem to be able to compile because I cann't > have any constructor in the BeanClass (O'Reilly book), which I do have in > the original class that the bean should substitute:-( > I know, normlly the stuff in the constructor is done in the ejbCreate, but > in my case, I have invokation of super() in the constructor, which is of > course bad for EJB. But it didn't work even if I don't use the super() but > move the init code from super class to the bean, compiler simply says it > cann't deal with the constructor in the super class:-( > Now I'm wondering, is it that I've done something wrong or is such thing > not > possible by definition? Anyone with experience here, comments are heartily > welcome! > Also, another question would be: If the purpose of an EJB is to substitute > some normal class, should I put it in it's own package, or should I leave > it > in the original package? If I put it in a new package, then many > "protected" > access modifier has to be "cracked open" to "public" in the original > package, which seems hairy to me. But I don't know whether it's > possible/feasible to package EJBs with the normal classes and make them > one > big jar, will the app server have any problem with it? > The problems are quite urgent and I'm looking forward to your reply! > Many thanks in advance! > > regards > ZHU Jia > > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-user If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please refer to http://www.drkw.com/disc/email/ or contact the sender. ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] Help! - Can EJB inherit from normal classes? Packaging with normal classes?
i would refactor honestly. its probably too much of a pain to try and keep these classes in the inheritance structure of an ejb. you can read some examples of how to inherit things in the RMH book. But its mostly aimed at new development. Since the bean instantiation class implements entityBean you could have it extend your class, so now you have implementation in the instantiation, however now you have to synchronize the remote interface, which already extends EJBObject, so you are stuck putting all the method signatures in there anyway. its still going to take a pretty decent amount of work since you are going to have to check all your classes to ensure you are not doing something "funky" in the implementation class, or something outright disallowed. With all the time spent going through the code I would just refactor it anyway, rather than try to make it work in EJB. Al > >Hello, > > > >I've a question on inheritence in EJB. > >As I'm working on the adaption of an existing Java framework, I have to > >convert many normal Java classes to EJB. But I'm not sure what to do with > >the inheritence. Someone in the list suggested I let the RemoteInterface > >inherit from some super interface and let the BeanClass inherit from the > >super implementation. This way, if a type of the super interface is > >expected, then an EJB RemoteInterface can be returned, which looks quite > >reasonable to me, so I was trying to do just that. > >But the problem is, I didn't seem to be able to compile because I cann't > >have any constructor in the BeanClass (O'Reilly book), which I do have in > >the original class that the bean should substitute:-( > >I know, normlly the stuff in the constructor is done in the ejbCreate, but > >in my case, I have invokation of super() in the constructor, which is of > >course bad for EJB. But it didn't work even if I don't use the super() but > >move the init code from super class to the bean, compiler simply says it > >cann't deal with the constructor in the super class:-( > >Now I'm wondering, is it that I've done something wrong or is such thing not > >possible by definition? Anyone with experience here, comments are heartily > >welcome! > >Also, another question would be: If the purpose of an EJB is to substitute > >some normal class, should I put it in it's own package, or should I leave it > >in the original package? If I put it in a new package, then many "protected" > >access modifier has to be "cracked open" to "public" in the original > >package, which seems hairy to me. But I don't know whether it's > >possible/feasible to package EJBs with the normal classes and make them one > >big jar, will the app server have any problem with it? > >The problems are quite urgent and I'm looking forward to your reply! > >Many thanks in advance! > > > >regards > >ZHU Jia > > > > > >___ > >JBoss-user mailing list > >[EMAIL PROTECTED] > >http://lists.sourceforge.net/lists/listinfo/jboss-user > > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] Help! - Can EJB inherit from normal classes? Packaging with normal classes?
We do use inheritance of the BeanClass from a normal class but we don't use constructors of the baseclass, just calling methods. And we put the normal baseclass (and other normal classes used from the beans) and the BeanClass in the same package and one jar. It works very well for us. Ciao Annegret > -Original Message- > From: ZHU Jia [SMTP:[EMAIL PROTECTED]] > Sent: Dienstag, 3. Juli 2001 07:28 > To: EJBList; [EMAIL PROTECTED] > Cc: jboss-user > Subject: [JBoss-user] Help! - Can EJB inherit from normal classes? > Packaging with normal classes? > > Hello, > > I've a question on inheritence in EJB. > As I'm working on the adaption of an existing Java framework, I have to > convert many normal Java classes to EJB. But I'm not sure what to do with > the inheritence. Someone in the list suggested I let the RemoteInterface > inherit from some super interface and let the BeanClass inherit from the > super implementation. This way, if a type of the super interface is > expected, then an EJB RemoteInterface can be returned, which looks quite > reasonable to me, so I was trying to do just that. > But the problem is, I didn't seem to be able to compile because I cann't > have any constructor in the BeanClass (O'Reilly book), which I do have in > the original class that the bean should substitute:-( > I know, normlly the stuff in the constructor is done in the ejbCreate, but > in my case, I have invokation of super() in the constructor, which is of > course bad for EJB. But it didn't work even if I don't use the super() but > move the init code from super class to the bean, compiler simply says it > cann't deal with the constructor in the super class:-( > Now I'm wondering, is it that I've done something wrong or is such thing > not > possible by definition? Anyone with experience here, comments are heartily > welcome! > Also, another question would be: If the purpose of an EJB is to substitute > some normal class, should I put it in it's own package, or should I leave > it > in the original package? If I put it in a new package, then many > "protected" > access modifier has to be "cracked open" to "public" in the original > package, which seems hairy to me. But I don't know whether it's > possible/feasible to package EJBs with the normal classes and make them > one > big jar, will the app server have any problem with it? > The problems are quite urgent and I'm looking forward to your reply! > Many thanks in advance! > > regards > ZHU Jia > > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] Help! - Can EJB inherit from normal classes? Packaging with normal classes?
I read an article in Javaworld.com about converting existing classes to EJB. You may want to have a look there. Devraj At 07:28 3/07/01 +0200, you wrote: >Hello, > >I've a question on inheritence in EJB. >As I'm working on the adaption of an existing Java framework, I have to >convert many normal Java classes to EJB. But I'm not sure what to do with >the inheritence. Someone in the list suggested I let the RemoteInterface >inherit from some super interface and let the BeanClass inherit from the >super implementation. This way, if a type of the super interface is >expected, then an EJB RemoteInterface can be returned, which looks quite >reasonable to me, so I was trying to do just that. >But the problem is, I didn't seem to be able to compile because I cann't >have any constructor in the BeanClass (O'Reilly book), which I do have in >the original class that the bean should substitute:-( >I know, normlly the stuff in the constructor is done in the ejbCreate, but >in my case, I have invokation of super() in the constructor, which is of >course bad for EJB. But it didn't work even if I don't use the super() but >move the init code from super class to the bean, compiler simply says it >cann't deal with the constructor in the super class:-( >Now I'm wondering, is it that I've done something wrong or is such thing not >possible by definition? Anyone with experience here, comments are heartily >welcome! >Also, another question would be: If the purpose of an EJB is to substitute >some normal class, should I put it in it's own package, or should I leave it >in the original package? If I put it in a new package, then many "protected" >access modifier has to be "cracked open" to "public" in the original >package, which seems hairy to me. But I don't know whether it's >possible/feasible to package EJBs with the normal classes and make them one >big jar, will the app server have any problem with it? >The problems are quite urgent and I'm looking forward to your reply! >Many thanks in advance! > >regards >ZHU Jia > > >___ >JBoss-user mailing list >[EMAIL PROTECTED] >http://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user