persistence@glassfish.java.net

RE: AW: Bug Comparing Enum with Bindingparameter

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Mon, 28 Jan 2008 16:21:57 -0500

This is a bug, please file a bug for this. As a workaround you can change the order of the enum comparison putting the 'is null' second.
--Gordon

@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 (pcl.planningRelationType = :planningRelationType or :planningRelationType is null)"

                     + " order by po.name"

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


  And the exceptionstack:

  invalid enum equal expression, cannot compare enum value of type [de.encom.fourpro.plannings.data.PlanningRelationType} with a non enum value of type [java.lang.Object].

              at oracle.toplink.essentials.exceptions.EJBQLException.invalidEnumEqualExpression(EJBQLException.java:484)

              at oracle.toplink.essentials.internal.parsing.EqualsNode.validate(EqualsNode.java:70)

              at oracle.toplink.essentials.internal.parsing.OrNode.validate(OrNode.java:77)

              at oracle.toplink.essentials.internal.parsing.Node.validate(Node.java:118)

              at oracle.toplink.essentials.internal.parsing.LogicalOperatorNode.validate(LogicalOperatorNode.java:63)

              at oracle.toplink.essentials.internal.parsing.WhereNode.validate(WhereNode.java:58)

              at oracle.toplink.essentials.internal.parsing.ParseTree.validate(ParseTree.java:235)

              at oracle.toplink.essentials.internal.parsing.ParseTree.validate(ParseTree.java:211)

              at oracle.toplink.essentials.internal.parsing.ParseTree.validate(ParseTree.java:201)

              at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateReadQueryInternal(EJBQLParseTree.java:134)

              at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.populateQuery(EJBQLParseTree.java:108)

              at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:219)

              at oracle.toplink.essentials.queryframework.EJBQLPlaceHolderQuery.processEjbQLQuery(EJBQLPlaceHolderQuery.java:111)

              at oracle.toplink.essentials.internal.sessions.AbstractSession.processEJBQLQueries(AbstractSession.java:2059)

              at oracle.toplink.essentials.internal.sessions.AbstractSession.processEJBQLQueries(AbstractSession.java:2046)

              at oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:724)

              at oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:604)

              at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:280)

              at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:229)

              at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:93)

              at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:126)

              at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:99)

              at com.sun.enterprise.util.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:326)

              at com.sun.enterprise.util.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:660)

   


------------------------------------------------------------------------------

  Von: Christian Kerwer [mailto:Christian.Kerwer_at_t-online.de]
  Gesendet: Montag, 28. Januar 2008 16:35
  An: persistence_at_glassfish.dev.java.net
  Betreff: Bug Comparing Enum with Bindingparameter

   

  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?