3 Replies Latest reply on Nov 17, 2005 5:59 AM by epbernard

    UserType and EJB-QL

    ajwhitney

      I'm porting an existing application which used to use Hibernate for persistence to EJB3. I am having difficultly porting some queries that rely on a custom type and am looking for some help.

      This application contains a base type Base which has an Id that is a custom type. It is marked in the entity bean with @Id and @Type (and @GenericGenerator since it has a custom generation strategy). There is a custom UserType for this id type just as there was in Hibernate (as referenced with the @Type annotation).

      There is a subclass Subclass which extends Base (and uses inheritance type JOINED if that matters).

      In Hibernate, I would query for a Subclass with particular Id like so:

      Query q = session.createQuery("FROM Subclass s WHERE s.customId = :id");
      q.setParameter("id", customIdInstance, Hibernate.custom(CustomIdType.class));
      // execute query

      I don't see a similar method on EJB-QL Query. Currently, I do:

      Query q = em.createQuery("FROM Subclass s WHERE s.customId = :id");
      q.setParameter("id", customIdInstance);
      // execute query

      This compiles, of course, but this doesn't execute correctly. I assume this is because I am not providing the type information for the query API to determine how to generate the bind variable value.

      What is the correct way to do this in EJB3?

      Thanks,
      A.J.
      ajwhitney@clearprogress.com

        • 1. Re: UserType and EJB-QL
          epbernard

          We're working on this one. In the meanwhile, fallback to a hibernate session and use the hibernate query

          • 2. Re: UserType and EJB-QL
            ajwhitney

            Thanks for the help. That's easy enough for the short term.

            Is this feature scheduled for a particular release? Do you know if there are plans for adding custom types to the spec so that this type of thing would be portable?

            • 3. Re: UserType and EJB-QL
              epbernard

               

              "ajwhitney" wrote:
              Is this feature scheduled for a particular release? Do you know if there are plans for adding custom types to the spec so that this type of thing would be portable?

              Unfortunatly this is not going to happen for this spec. Do not hesitate to put pressure on the EJB3 EG through mail though.