CMP combined with Session beans using JDBC

Discussions

EJB programming & troubleshooting: CMP combined with Session beans using JDBC

  1. CMP combined with Session beans using JDBC (6 messages)

    Hi,

    Assuming that there is no EJB-QL equivalent for the SQL COUNT(*) and MAX(...) functions, would it be safe to combine CMP entity beans with stateless session beans, where the session beans would use true SQL calls via JDBC to access the same tables as the CMP entity bean?

    E.g. the CMP entity bean would have the regular findByPrimaryKey, findAll, etc. methods, and the stateless session bean would have methods such as Count(), MaxSalary(), etc.

    Or would this result in horrible caching issues?
  2. Yes. EJB's are designed with the possibility that the same data store may be accessed by another legacy application concurrently. In fact, this is the prime reason for the overhead in the Entity Beans. You can control how much concurrency you would like by setting the Transaction Isolation level in the EJB.

    It looks like you will only be reading the DB from the SLSB. Even if you update, it doesn't matter.

    I am not sure if the EJB QL supports the functions you need. It has been a while since I looked at the specs.

    Thanks...
    -Srini Santhanam
    RBC Dain Rauscher
  3. CMP combined with Session beans using JDBC[ Go to top ]

    I suggest that you don't use separate stateless session beans. Use entity beans's home methods.
  4. CMP combined with Session beans using JDBC[ Go to top ]

    In the meantime, I found out that aggregate functions (max, min, avg, count, ...) are in the 2.1 proposed final spec, but it will probably be a while before the application server vendors get their apps up to that level.

    About the "Use entity bean's home methods":

    Can I use JDBC statements inside a CMP entity bean home method?
  5. No jdbc calls shouldnt be made in a cmp.
  6. Posted by gopal krishnan 2002-09-16 02:15:19.0.
    > No jdbc calls shouldnt be made in a cmp.

    I see no reason for such a restriction, as long as both the CMP's data source and the JDBC datasource are XA compliant.
  7. If your purpose of doing so it to get the highest Id then this can be done by creating a sequence and then using the nextval.This will give you the highest value.