Sorry that didn't work ...

If I'm reading it correctly, 
- in the DB you have a column "GEN_STATUS" which is a number type (integer?)
- this number corresponds to your enumeration as the ordinal position
- in the result, you want to show the number (and sort the results based on it)

Is that correct?

If so, why are you trying to transform the results?

John



 

> -----Ursprüngliche Nachricht-----
> Von: it-media.k...@daimler.com [mailto:it-media.k...@daimler.com] 
> Gesendet: Mittwoch, 17. Oktober 2012 09:47
> An: users@openjpa.apache.org
> Betreff: Antwort: AW: @Enumerated(EnumType.ORDINAL) in JPQL 
> CASE WHEN generates invalid SQL using name of Enumeration 
> member, not ordinal
> 
> Hello,
> 
> that is not working, as you cannot simply use a method call 
> withni JPQL ... I think this is a severe bug in the implementation.
> 
> I tried to build up a query like this using Criteria API and 
> Criteria API only allows to provide the enumeration at all 
> when using a selectCase(), but the generated SQL is wrong too. 
> 
> This should be fixed, as the @Enumeration annotation's type 
> is not taken into account when generating the resulting XML.
> 
> Regards,
> 
> Heiko
> 
> --
> Dr.-Ing. Heiko Kopp / Fa. Vision iT media GmbH
> 
> 
> 
> 
> john.bobl...@bertschi.com
> 10.10.2012 17:55
> Bitte antworten an
> users@openjpa.apache.org
> 
> 
> An
> users@openjpa.apache.org
> Kopie
> 
> Thema
> AW: @Enumerated(EnumType.ORDINAL) in JPQL CASE WHEN generates 
> invalid SQL 
> using name of Enumeration member, not ordinal
> 
> 
> 
> 
> 
> 
> Hello,
> 
> Shouldn't you be using 
> 
>                  WHEN 
> model.protocol.ApprovalState.IN_PROCESS.ordinal() 
> THEN 1
> 
> Just an idea ...
> 
> John
> 
> 
> > -----Ursprüngliche Nachricht-----
> > Von: it-media.k...@daimler.com [mailto:it-media.k...@daimler.com] 
> > Gesendet: Mittwoch, 10. Oktober 2012 11:18
> > An: users@openjpa.apache.org
> > Betreff: @Enumerated(EnumType.ORDINAL) in JPQL CASE WHEN 
> > generates invalid SQL using name of Enumeration member, not ordinal
> > 
> > Hello,
> > 
> > I've come across an issue with a column used within a JQPL 
> > CASE WHEN Selection.
> > 
> > The column's definition is as follows:
> > 
> >     @Column(name = "GEN_STATUS")
> >     @Enumerated(EnumType.ORDINAL)
> >     private ApprovalState state;
> > 
> > The JPQL used here is
> > 
> > SELECT c, 
> >         ( CASE c.approval.state 
> >                 WHEN model.protocol.ApprovalState.IN_PROCESS THEN 1 
> >                 WHEN 
> > model.protocol.ApprovalState.RELATION_CHECK THEN 2
> >                 WHEN model.protocol.ApprovalState.IN_APPROVAL THEN 3
> >                 WHEN 
> model.protocol.ApprovalState.NEEDS_SCORING THEN 4
> >                 WHEN
> > model.protocol.ApprovalState.ADOPTION_REQUEST_IN_PROCESS THEN 5
> >                 WHEN 
> > model.protocol.ApprovalState.ADOPTION_REQUESTED THEN
> > 6
> >                 WHEN model.protocol.ApprovalState.APPROVED THEN 7
> >                 WHEN
> > model.protocol.ApprovalState.APPROVED_WITH_COLLATERALS THEN 8
> >                 WHEN model.protocol.ApprovalState.ACTIVATED THEN 9
> >                 WHEN model.protocol.ApprovalState.CANCELLED THEN 10
> >                 WHEN model.protocol.ApprovalState.DECLINED THEN 11
> >                 WHEN model.protocol.ApprovalState.CREATED THEN 12
> >                 WHEN model.protocol.ApprovalState.DEDUCTED THEN 13
> >                 WHEN model.protocol.ApprovalState.DELETED THEN 14
> >                 WHEN 
> > model.protocol.ApprovalState.PROPOSAL_CANCELLED THEN
> > 15
> >                 ELSE 0
> >           END ) AS vehicleStateOrder
> > FROM DbContract c WHERE c.person.personId = :personId ORDER 
> > BY vehicleStateOrder, c.insertDate
> > 
> > However, when this JPQL is transferred to SQL, e.g. ORACLE in 
> > this case throws the following error:
> > 
> > ORA-00932: Inkonsistente Datentypen: NUMBER erwartet, CHAR erhalten
> > 
> > A relevant part of the query is:
> > 
> > SELECT * FROM (SELECT t0.VTR_ID AS c0,  CASE t2.GEN_STATUS 
> > WHEN 'IN_PROCESS' THEN 1 WHEN 'RELATION_CHECK' THEN 2 WHEN 
> > 'IN_APPROVAL' ...
> > 
> > The problem here is, that as the column definition denotes, 
> > not the ordinal number, but the enumeration name is used. 
> > 
> > Wer are using WebSphere 8.0.0.4 which includes 
> > openjpa-2.1.2-SNAPSHOT-r422266:1333100.
> > 
> > Can somebody please tell me, what we can do to get this query 
> > working or is this a bug in the JPQL parsing system?
> > 
> > Best regards,
> > 
> > Heiko
> > 
> > --
> > Dr.-Ing. Heiko Kopp / Fa. Vision iT media GmbH
> > 
> > If you are not the intended addressee, please inform us 
> > immediately that you have received this e-mail in error, and 
> > delete it. We thank you for your cooperation. 
> 
> 
> If you are not the intended addressee, please inform us 
> immediately that you have received this e-mail in error, and 
> delete it. We thank you for your cooperation.  

Reply via email to