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

    UserType and EJB-QL

    AJ Whitney Newbie

      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?