EJBQL (EJB2.1) and strange results

From: Nikolaj Hansen (nico_at_mailinator.com)
Date: 03/17/05


Date: Thu, 17 Mar 2005 12:38:20 +0100

Hi all,

I am writing a CMP layer for a database using XDOCLET. That's ok, the
problem is with a finder, and results I simply cannot understand.

  * @ejb.finder
  * signature="java.util.Collection findMax()"
  * query="SELECT OBJECT(a) FROM ProcessInstancesSchema AS A WHERE
a.id = (SELECT MAX(b.id) FROM ProcessInstancesSchema b)"

This returns two rows. On all beans - not just the one mentioned above.
I tried moving the finder onto another bean with identical results. What
  I need to find is the largest key value on a bean (id). On a normal
database it would be:

select max(foo) from bar;

Easy peacy, but not in EJBQL. The finder must return a bean interface,
thats why there's a sub select in the finder method. The nested select
finds the max key, and the outer select reads the entire row for input
to the bean interface. In normal sql:

select * from bar where bar.id = (select max(bar.id) from bar);

However the above EJBQL ALWAYS returns two identical bean instances?
There can only be one...

regards

Nikolaj Hansen



Relevant Pages

  • Re: EJB find methods. Why do they return only the primary key?
    ... > building the bean and returning it in the find method. ... database has a record with that primary key. ... returns the primary key; if not it throws an ObjectNotFoundException. ... the finder must throw an ObjectNotFoundException. ...
    (comp.lang.java.programmer)
  • Re: J2EE - entities - When do JPA entity units get saved into the database
    ... as JPA entities and EJB 2 Entity Beans have ... field changes back to the database if the changes occur within the ... same transaction that the entity was loaded in AND if the object has ... However, if the value of 'bean' escapes out of an ongoing transaction, ...
    (comp.lang.java.programmer)
  • Figuring out the Correct Approach <scratch head>
    ... database and place a object in the servletcontext ... I have a simple login page which is a jsp, ... The bean does not have a servletContext so it ...
    (comp.lang.java.databases)
  • Re: [jsp]: getProperty
    ... Ryan Stewart wrote: ... > database at a time and creating a single bean based on it? ... > to correspond to multiple bean values... ... original post work. ...
    (comp.lang.java.programmer)
  • Figuring out the correct approach.. :S
    ... database and place a object in the servletcontext ... I have a simple login page which is a jsp, ... The bean does not have a servletContext so it ...
    (comp.lang.java.programmer)