0 Replies Latest reply on Apr 30, 2006 12:56 AM by mazz

    query on embedded object failing

    mazz Master

      I'm not sure if I'm doing something wrong or if there is a problem with underlying EJB container.

      I have an entity with an @Embedded object along with some other fields directly defined in the entity (including its surrogate key which is an int). I want to query the object on just the embedded object.

      SELECT e FROM Entity e WHERE e.embedded=:embedded
      


      where I set the parameter "embedded" to my embedded POJO. That embedded object has a few fields in it - a Date (TemporalType=DATE), a couple int's, a String and an Integer (which may or may not be null - that column is nullable).

      When I try to execute this, I get a Postgres error under the covers:

      org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1.
      


      If I change my query such that I break out all the embeddable fields into individual clauses within the WHERE, it all works fine:

      SELECT
       e FROM Entity e
      WHERE
       e.embedded.stringcolumn=:p1 AND
       e.embedded.datecolumn=:p2 AND
       ...
      


      Is that first query I tried invalid for some reason?

      The only thing I noticed that I found weird was the hibernate show_sql output showing this:

      select
       entity0_.id as id4_,
       entity0_.value as value4_,
       entity0_.datecolumn as datecolumn3_4_,
       entity0_.stringcolumn as stringcolumn4_4_,
       ...
      from
       entity entity0_
      where
       (
       entity0_.datecolumn, entity0_.stringcolumn, ...
       )=?
      


      I cut out alot of the columns but you get the idea. The where statement has all the fields defined in my embedded object. But there is only a single parameter (notice only one ?) and in the debug messages I can see hibernate only adding the single parameter to the query (that being my embedded POJO). But, the where clause has many more columns than just one, as you can see. (BTW: side question - is it possible to get the show_sql output to show me the actual parameter values, as opposed to just the "?" - I'd like to see the values in the SQL output rather than hunting through other hibernate debug messages to find them).

      I'm not sure if I'm misreading the debug output and that SQL. But, this certainly isn't working. Again, if I break out and do my own WHERE clause with all the individual embedded fields, it all works fine.