0 Replies Latest reply on Aug 29, 2006 5:29 PM by Brett Birschbach

    Embedded Object in Where Clause

    Brett Birschbach Newbie

      Is it possible to have an embedded object in the WHERE clause of a named query?

      Say you have a Customer entity with an Embedded Name object. Name contains first_name and last_name.

      If I write a named query accessing the pieces of Name directly, as in the below query, it works fine:
      SELECT cust FROM Customer cust WHERE cust.name.first_name = :firstName AND cust.name.last_name = :lastName

      However, if I try to access the entire Name object in the query, the query fails:
      SELECT cust FROM Customer cust WHERE cust.name = :name

      The funny thing is, if I put the server in DEBUG logging mode, and I attempt the second query, the query sent to the database is:
      SELECT cust.field1, cust.field2 FROM customer cust WHERE (cust.first_name, cust.last_name) = ? To me, it looks like EJB is smart enough to realize that my Name object is an embedded object pointing to two fields in the customer table. However, it is not smart enough to realize that it needs to split up the parameter passed in to the named query into its respective pieces, since I get a SQL error stating "invalid relational operator".

      Is this just how things are?