Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Enum literals in JPQL IN expressions(How to use enum literals in JPQL IN expressions)
Enum literals in JPQL IN expressions [message #540481] Wed, 16 June 2010 10:52 Go to next message
Thomas is currently offline ThomasFriend
Messages: 10
Registered: June 2010
Junior Member
Hi,

I am trying to use Enum literals in JPQL IN expressions to select all Phones with a specific PhoneType where PhoneType is a Java Enum. The JPQL query is:

SELECT p FROM Phone p WHERE p.type IN (my.package.PhoneType.Home, my.package.PhoneType.Work)

This results in a Syntax error while parsing the query.
Exception Description: Syntax error parsing the query [nonMobilePhones: SELECT p FROM Phone p WHERE p.type IN (my.package.PhoneType.Home, my.package.PhoneType.Work)], line 1, column 41: syntax error at [.].

Can anyone give me a hint how this query has to be formulated with correct syntax?

Thanks,
Thomas
Re: Enum literals in JPQL IN expressions [message #540524 is a reply to message #540481] Wed, 16 June 2010 12:56 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello Thomas,

Try adding enums as parameters:
SELECT p FROM Phone p WHERE p.type IN ( :param1 , :param2 )

query.setParameter("param1",
my.package.PhoneType.Home);
query.setParameter("param2", my.package.PhoneType.Work)

Best Regards,
Chris

Re: Enum literals in JPQL IN expressions [message #540592 is a reply to message #540524] Wed, 16 June 2010 15:32 Go to previous messageGo to next message
Thomas is currently offline ThomasFriend
Messages: 10
Registered: June 2010
Junior Member
Hi Chris,

thanks for your hint. I think that would solve my problem. I am using another workaround at the moment. I've reformulated my query to:

SELECT p FROM Phone p WHERE p.type=my.package.PhoneType.Home OR p.type=my.package.PhoneType.Work


This works fine too but I would have preferred my first JPQL query.

The EJB 3.0 specification contains the following specification of IN expressions:

in_expression ::=
state_field_path_expression [NOT] IN ( in_item {, in_item}* | subquery)

in_item ::= literal | input_parameter

The state_field_path_expression must have a string, numeric, or enum value.
The literal and/or input_parameter values must be like the same abstract schema type of the
state_field_path_expression in type. (See Section 4.12).


The sentence "literal values must be like the same abstract schema type of the ..." sounds like the usage of enum literals in IN expressions should be possible. Is there a way to use them in JPQL or is this perhaps not yet supported by EclipseLink?

Regards,
Thomas
Re: Enum literals in JPQL IN expressions [message #540888 is a reply to message #540481] Thu, 17 June 2010 14:39 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What version of EclipseLink are you using? Could you try the 2.1 release.


James : Wiki : Book : Blog : Twitter
Re: Enum literals in JPQL IN expressions [message #542541 is a reply to message #540888] Fri, 25 June 2010 09:27 Go to previous message
Thomas is currently offline ThomasFriend
Messages: 10
Registered: June 2010
Junior Member
Hi James,

sorry for the late reply.
We are currently using EclipseLink 2.0.2.
I've tested the scenario with EclipseLink 2.1. Seems that the problem has been fixed in that version. Everything works fine with EclipseLink 2.1.

Thanks for the hint.

Regards,
Thomas
Previous Topic:Inherited OneToOne relationship not hydrated properly
Next Topic:org.eclipse.persistence.exceptions.ValidationException thrown due to NegativeArraySizeException
Goto Forum:
  


Current Time: Fri Apr 19 10:50:20 GMT 2024

Powered by FUDForum. Page generated in 0.01981 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top