persistence@glassfish.java.net

Bug Comparing Enum with Bindingparameter

From: Christian Kerwer <Christian.Kerwer_at_t-online.de>
Date: Mon, 28 Jan 2008 16:35:18 +0100

Here ist the NamedQuery:

@NamedQuery(

               name =
"PlanningObjectLink-ChildrenWithRelationTypeAndStructureId",

               query = "select lnk"

                     + " from PlanningObjectLink lnk, PlanningObject po"

                     + " join lnk.planningClassLink pcl"

                     + " join lnk.reference lref"

                     + " join lnk.parent lp"

                     + " join pcl.structureList pcs"

                     + " where lp.id = :planningObjectId"

                     + " and pcs.id = :planningClassStructureId"

                     + " and lref = po and " +
PlanningAuthClauses.AUTH_PLAN_OBJ_CLAUSES

                     + " and (:planningRelationType is null or
pcl.planningRelationType = :planningRelationType)"

                     + " order by po.name"

 

This is the joined Entity Field (in Entity PlanningClassLink)

   @Enumerated(value=EnumType.STRING)

   @Column( name = "RELATIONTYPE" )

   private PlanningRelationType planningRelationType;

 

And this is the execution:

Query v_Query = getEntityManager().createNamedQuery(
"PlanningObjectLink-ParentsWithRelationTypeInStructureId" );

      v_Query.setParameter( "planningObjectId", p_PlanningObject.getId() );

      v_Query.setParameter( "planningClassStructureId",
p_PlanningClassStructure.getId() );

      

      if (p_FollowOnlyPrimaryLinks)

      {

         v_Query.setParameter( "planningRelationType",
PlanningRelationType.PRIMARY.toString() );

      }

      else

      {

         v_Query.setParameter( "planningRelationType", null );

      }

         

      // Hier muß die Rechteprüfung ausgeschaltet sein!

      v_Query.setParameter( "isAdmin", true );

      v_Query.setParameter( "funcKey", null );

      v_Query.setParameter( "userId", null );

      

      List<PlanningObjectLink> v_LinksToParenst;

      try

      {

         v_LinksToParenst = (List<PlanningObjectLink>)
v_Query.getResultList();

      }

      catch( IllegalStateException e )

      {

         throw new DAOException( this, e );

      }

      catch( IllegalArgumentException e )

      {

         throw new DAOException( this, e );

      }

 

  _____

Von: Gordon Yorke [mailto:gordon.yorke_at_oracle.com]
Gesendet: Montag, 28. Januar 2008 16:18
An: persistence_at_glassfish.dev.java.net
Betreff: RE: Bug Comparing Enum with Bindingparameter

 

Can you provide the section of code that is setting the parameter and
executing the query. Can you send a bit more of the stack trace?

--Gordon

-----Original Message-----
From: Christian Kerwer [mailto:Christian.Kerwer_at_t-online.de]
Sent: Monday, January 28, 2008 9:50 AM
To: persistence_at_glassfish.dev.java.net
Subject: Bug Comparing Enum with Bindingparameter

Hello,

 

I’m experiencing a problem with NamedQueries.

In den following example in a NamedQuery an enum-field is to be compared
with an binding-parameter.

There’s no reason why this is not allowed, since it is possible to bind enum
parameter with ‚query.setParameter()’.

 

Toplink quits this issue with the following reason:

invalid enum equal expression, cannot compare enum value of type
[MyEnumType] with a non enum value of type [java.lang.Object]

 

Anyone an idea?