I'm finding EJBs extremely annoying and/or counter-intuitive at the moment. Here's the problem.
I have a CMP 2.0 entity
EJB called
LiveOrder which contains information about an order (runs on Weblogic 7.0). These are stored in an Oracle 9i DB. There are times when I wish to retrieve a sorted subset of these orders. Unfortunately GROUPBY won't be supported until the EJB 2.1 spec, and I don't want to start writing
JDBC calls directly.
Well, the obvious solution is to use Collections. I created a
findBy method and passed in the EJB-SQL commands using JBuilder 8 Enterprise. This returns a Collection. So far so good. Now here's the great part, I just need to make that object (
LiveOrder) implement the
Comparable interface and then dump it in a
TreeSet and it will do the sorting for me. Easy! (The level of sorting is a simple two level sort based on numbers, even easier then the example they give in the Collection's tutorial.)
Here's where the problem comes in. I wrote the following code:
There is a big problem. The
Collection isn't of
LiveOrder, but rather some class called
LiveOrderBean_lg3vj2_ELOImpl -- one of those autogenerated EJB classes. This gives me a [i]ClassCastException. (Also, it was using the
toString() of the new class and not the one I overrode in LiveOrder, but that's fixable by creating another method like
getString().)
So then I tried to be clever. I created a [/]LiveOrderComparableInterface[/i] as follows
This had all the methods I needed to access. So now my sort method can look like
The only problem is that I still get a
ClassCastException! Even more interesting, when I got the interfaces after calling
getClass().getInterfaces(), I found the following information:
class: LiveOrderBean_lg3vj2_ELOImpl interfaces: LiveOrder weblogic.utils.PlatformConstants Serializable Surely others have been down this road before? Does anyone have any ideas? Do EJBs really suck this much, not allowing simple intuitive actions, or am I missing something?
--Mark
[ January 22, 2003: Message edited by: Mark Herschberg ]