Using ejb-ql at runtime?


EJB design: Using ejb-ql at runtime?

  1. Using ejb-ql at runtime? (1 messages)

         I've got an interesting problem that I'm trying to solve with CMP entity beans... this kind of thing may be interesting to other developers, so I thought I'd just toss it out in the public domain to see if anyone has any feedback or suggestions on it.

         I'm expanding an existing servlet & beans application to make use of EJB's. The current system is using your basic MVC design pattern, with an extra layer or two thrown in. For instance, there's an extra "mapping" layer underneath the model layer. This mapping layer hooks the model objects into permenant storage (we have mappers for JDBC, message queue systems, XML, etc)... as model objects are created, updated, and deleted, the mapping layer handles the persistence.

         We're migrating to entity beans for persistance... but it's not going to happen all at once, and we'll need to retain the ability to map to those other persistance mediums as well. Therefore, we're just creating an entity bean layer beneath the mapping layer... and will need to create a new mapping object to handle the mapping between the EJB's and the existing model objects used by the system.

         What I would really like is to have one "EJBMapper" object that can dynamically map any entity bean to a plain Java model object. I envision storing the information about each EJB-to-vanilla-Java-object relationship in an XML file that the mapper object loads at boot-time... with that information allowing it to implement the methods "returnAllObjects()", "returnObjectsMatching(<expression>)", etc for each entity bean type at run-time.

         It seems that EJB-QL would be the perfect fit for these expressions. My generic mapper could load the appropriate EJB-QL query from the XML descriptor for a particular bean, and have that passed to a finder method on the bean's home interface that takes in an EJB-QL string as its input parameter.

         The problem is that, as I understand it, EJB-QL is a deploy-time thing... you use it in the deployment descriptor when you're building your JAR, but you can't use it at run-time. I know that WebLogic has some CMP extentions for using EJB-QL at run-time... but I have to support multiple server environments (WebLogic, WebSphere, and JBoss), so I'm not sure if there's some standards-based solution for accomplishing what I need.

         Basically I just curious if my understanding of EJB-QL is flawed, and it can in fact be used at run-time after all in some manner. If not, I was wondering if anyone else has ever implemented a solution like this before... or if there is some design pattern they can think of that might help out better.

    Threaded Messages (1)

  2. some suggestion[ Go to top ]

      why not use a session bean as a factory ,the entity-beans will be the product which genernated by the factory?based on more patterns (such as builder or abstract factory),u can do it!