3 Replies Latest reply on Sep 28, 2007 9:46 AM by steve tynor

    Inheritence and EJBQL

    steve tynor Novice

      Can EJBQL be used to query polymorphically? I cannot find any examples in the spec or in Bill Burke's EJB3 book, and my attempts are always returning null.

      l = entityManager.createQuery("SELECT s FROM Security s").getResultList();


      Here I'm trying to find all rows of all security subclasses. Even though the database has many such entries, the query always returns null. I can find each subclass independently - eg.:
      l = entityManager.createQuery("SELECT s FROM SecurityLoan s").getResultList();
      l = entityManager.createQuery("SELECT s FROM SecurityEquity s").getResultList();


      but would like to write a single query to get all objects, regardless of subclass.

      My entities are declared using JOINED inheritence:

      @Entity
      @Table(name = "security")
      @Inheritance(strategy = InheritanceType.JOINED)
      public class Security implements java.io.Serializable {
      ....
      @Entity
      @Table(name = "security_loan")
      @PrimaryKeyJoinColumn(name="security_id")
      public class SecurityLoan extends Security implements java.io.Serializable {
      ....
      @Entity
      @Table(name = "security_equity")
      @PrimaryKeyJoinColumn(name="security_id")
      public class SecurityEquity extends Security implements java.io.Serializable {
      


      Is this possible?

        • 1. Re: Inheritence and EJBQL
          steve tynor Novice

          I don't want to be a pest, but could someone at least tell me if what I'm trying to do should work (hence I should try harder to understand what I've misconfigured), or if I should just give up and use my work around (separate queries for each subclass)?

          I'm using JBoss AS 4.2.1.GA and Seam 2.0.0.CR1

          Thanks

          Can EJBQL be used to query polymorphically? I cannot find any examples in the spec or in Bill Burke's EJB3 book, and my attempts are always returning null.

          Code:
          l = entityManager.createQuery("SELECT s FROM Security s").getResultList();


          Here I'm trying to find all rows of all security subclasses. Even though the database has many such entries, the query always returns null. I can find each subclass independently - eg.:



          • 2. Re: Inheritence and EJBQL
            Wolfgang Knauf Master

            Hi !

            this should work. I have done the same by declaring named queries on each of the bean classes.

            you could take a look at this sample:
            http://www.informatik.fh-wiesbaden.de/~knauf/SWTVertiefung2007/kucheninheritance/KuchenInheritance.ear
            Unfortunately the language is german, but hope you can make your way through the code.
            The application client calls finder methods to load
            -all beans of all subtypes
            -all beans of subtype a
            -all beans of subtype b

            Hope his helps

            Wolfgang

            • 3. Re: Inheritence and EJBQL
              steve tynor Novice

              Thanks Wolfgang, that's very helpful!

              I don't see anything obviously different in your code vs. mine, but knowing that this works for you, I'll now start getting serious about finding my error. I'll report back to the thread when I fix it.

              Thanks again,
              Steve