Uploaded image for project: 'JBoss Enterprise Application Platform 4 and 5'
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-5590

EntityQuery.resultCount throws a exception when the entity has composite key

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • EAP_EWP 5.1.1
    • EAP 5.0.1, EAP 5.1.0 Post Release
    • Seam
    • None
    • Fedora 12, JDK 1.6, JBoss EAP 5.1, MySQL 5

    • Release Notes
    • Hide
      Invoking EntityQuery.resultCount() resulted in a query such as <code>select count( entity )...</code>. However, if the persistence provider is Hibernate and the Entity has a composite key, the exception <code>[ERROR JDBCExceptionReporter] Operand should contain 1 column(s)</code> is triggered, because Hibernate does not support composite keys in <code>count</code> queries.

      This constraint prevented you from using seam-gen and JBoss Developer Studio to generate CRUDs if you had Entities with composite keys and you use Hibernate. Hibernate extensively uses <code>EntityQuery.resultCount()</code> in the generated code, and this class triggered the exception.

      Seam has been updated, so that if the persistence provider is Hibernate, Seam builds the query using the notation <code>select count( * )</code> instead of <code>select count ( entity )</code>. This method works, even with composite keys. With this fix in place, <code>EntityQuery.resultCount()</code> works for all entities and all persistence providers, as do generated CRUDs.
      Show
      Invoking EntityQuery.resultCount() resulted in a query such as <code>select count( entity )...</code>. However, if the persistence provider is Hibernate and the Entity has a composite key, the exception <code>[ERROR JDBCExceptionReporter] Operand should contain 1 column(s)</code> is triggered, because Hibernate does not support composite keys in <code>count</code> queries. This constraint prevented you from using seam-gen and JBoss Developer Studio to generate CRUDs if you had Entities with composite keys and you use Hibernate. Hibernate extensively uses <code>EntityQuery.resultCount()</code> in the generated code, and this class triggered the exception. Seam has been updated, so that if the persistence provider is Hibernate, Seam builds the query using the notation <code>select count( * )</code> instead of <code>select count ( entity )</code>. This method works, even with composite keys. With this fix in place, <code>EntityQuery.resultCount()</code> works for all entities and all persistence providers, as do generated CRUDs.
    • Documented as Resolved Issue

      Hibernate has a known trouble running queries using "count" when the entity has composite keys, like: select count(foobar) from Foobar foobar:

      • ERROR [JDBCExceptionReporter] Operand should contain 1 column(s)

      Seam EntityQuery has a workaround, using count instead of count(alias)(spec way) if you use entityQuery.resultCount.
      It's works with Seam 2.0.x but no more in Seam 2.2.x

              rhn-support-alazarot Alessandro Lazarotti
              rhn-support-alazarot Alessandro Lazarotti
              Misty Stanley-Jones Misty Stanley-Jones (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: