Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPA Query + enum question

Hi James,

I tried the code, but I get
Internal Exception: java.sql.SQLException: Invalid column type.
Error Code: 17004

@NamedQuery(name = "findRequestInProcessingStage", query = "select r from ImportRequest r where r.importStage in(:stage1, :stage2)")

SELECT ID, REQUEST_DATE_TIME, REQUESTOR, IMPORT_COMMENT, IMPORT_STAGE, STAGE_INFORMATION, NUMBER_OF_ERRORS FROM PLI.PLI_IMPORT_REQUESTS WHERE (IMPORT_STAGE IN (?, ?))
   bind => [INIT, TRANSFORMED]

DAO:
ImportStage[] importStages = new ImportStage[ImportStage.getProcessingStages().size()];
   ImportStage.getProcessingStages().toArray(importStages);
Query query = getEntityManager().createNamedQuery("findRequestInProcessingStage");
    query.setParameter("stage1", ImportStage.INIT);
    query.setParameter("stage2", ImportStage.TRANSFORMED);

When I execute the sql in sqlplus, it works fine:
SELECT ID, REQUEST_DATE_TIME, REQUESTOR, IMPORT_COMMENT, IMPORT_STAGE, STAGE_INFORMATION, NUMBER_OF_ERRORS FROM PLI.PLI_IMPORT_REQUESTS WHERE (IMPORT_STAGE IN ('INIT', 'TRANSFORMED'))

What am I doing wrong?
Leon

James Sutherland wrote:
You should be able to query on enum types in JPQL, the same as an other basic
mapping.  JPQL does not allow :list arguments for IN, so you need to define
an argument for each value.  Technically EclipseLink could support list
arguments for IN, but I don't think does yet (although it is supported in
Expressions).

i.e.
@NamedQuery(name = "findRequestInStages", query = "select r from ImportRequest r where r.importStage in (:stage1, :stage2)")

getEntityManager().createNamedQuery("findRequestInStages").setParameter("stage1", ImportStage.value1).setParameter("stage2", ImportStage.value2).getResultList();


Leon Derks-2 wrote:
Is it possible to query for objects which have some kind of enum type?

For example :

@NamedQuery(name = "findRequestInStages", query = "select r from ImportRequest r where r.importStage in (:stages)")
//importStage is an Java 5 Enum.

getEntityManager().createNamedQuery("findRequestInStages").setParameter("stages", importStage is an Java 5 Enum.).getResultList();
//stages is an EnumSet.

I would like to get all the requests that have one of the given stages.

How can I do this?

Leon



-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink , http://wiki.oracle.com/page/TopLink TopLink Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , http://www.nabble.com/EclipseLink-f26430.html EclipseLink Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence



Back to the top