You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by twelveeighty <tw...@gmail.com> on 2014/01/04 23:50:37 UTC

Inner enum cannot be used as literal in JPQL

Can someone confirm whether or not this is a known issue, or if this is a
known limitation? 
When I define an  enum as part of my entity class, I am not able to use its
values as literals in a JPQL statement:

package com.myorg.jpa;
public Foo {
	public enum FooType { FOO, BAR }
	@Enumerated(EnumType.STRING)
	private FooType type;
}

select f from Foo f where f.type = com.myorg.jpa.Foo.FooType.BAR

Error message: Attempt to query field "com.myorg.jpa.Foo.FooType.BAR" from
non-entity variable "com". Perhaps you forgot to prefix the path in question
with an identification variable from your FROM clause?

My version: OpenJPA 2.3.0-nonfinal-1540826

However, if I take FooType and define it as its own Enum class
(com.myorg.jpa.FooType) the literal com.myorg.jpa.FooType.BAR works as
expected.

Should I log a bug for this?




--
View this message in context: http://openjpa.208410.n2.nabble.com/Inner-enum-cannot-be-used-as-literal-in-JPQL-tp7585806.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Inner enum cannot be used as literal in JPQL

Posted by twelveeighty <tw...@gmail.com>.
Ah.. Of course! I should have known better. The standard Java "inner class"
notation with $ does the trick.

Thanks Rick!


Rick Curtis wrote
> Try to change your query to : select f from Foo f where f.type =
> com.myorg.jpa.Foo$FooType.BAR
> 
> Thanks,
> Rick
> 
> 
> On Mon, Jan 6, 2014 at 9:19 AM, Kevin Sutter &lt;

> kwsutter@

> &gt; wrote:
> 
>> The use of a qualified enum value should be valid for JPQL.  But, the
>> spec
>> doesn't seem to specify whether the enum type needs to be in it's own
>> file
>> or not.  I've looked through the spec and some references and they all
>> seem
>> to assume that these enums are defined in it's file and not embedded
>> within
>> the Entity definition.
>>
>> I'd be hard pressed to consider this a bug.  Maybe a feature request, but
>> not a bug.  As you mentioned, if you define this enum separately,
>> everything works as expected, right?  Is there some reason why that
>> approach can't be done?
>>
>> Kevin
>>
>>
>>
>> On Sat, Jan 4, 2014 at 4:50 PM, twelveeighty &lt;

> twelve.eighty@

> &gt; >wrote:
>>
>> > Can someone confirm whether or not this is a known issue, or if this is
>> a
>> > known limitation?
>> > When I define an  enum as part of my entity class, I am not able to use
>> its
>> > values as literals in a JPQL statement:
>> >
>> > package com.myorg.jpa;
>> > public Foo {
>> >         public enum FooType { FOO, BAR }
>> >         @Enumerated(EnumType.STRING)
>> >         private FooType type;
>> > }
>> >
>> > select f from Foo f where f.type = com.myorg.jpa.Foo.FooType.BAR
>> >
>> > Error message: Attempt to query field "com.myorg.jpa.Foo.FooType.BAR"
>> from
>> > non-entity variable "com". Perhaps you forgot to prefix the path in
>> > question
>> > with an identification variable from your FROM clause?
>> >
>> > My version: OpenJPA 2.3.0-nonfinal-1540826
>> >
>> > However, if I take FooType and define it as its own Enum class
>> > (com.myorg.jpa.FooType) the literal com.myorg.jpa.FooType.BAR works as
>> > expected.
>> >
>> > Should I log a bug for this?
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> >
>> http://openjpa.208410.n2.nabble.com/Inner-enum-cannot-be-used-as-literal-in-JPQL-tp7585806.html
>> > Sent from the OpenJPA Users mailing list archive at Nabble.com.
>> >
>>
> 
> 
> 
> -- 
> *Rick Curtis*





--
View this message in context: http://openjpa.208410.n2.nabble.com/Inner-enum-cannot-be-used-as-literal-in-JPQL-tp7585806p7585811.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Inner enum cannot be used as literal in JPQL

Posted by Rick Curtis <cu...@gmail.com>.
Try to change your query to : select f from Foo f where f.type =
com.myorg.jpa.Foo$FooType.BAR

Thanks,
Rick


On Mon, Jan 6, 2014 at 9:19 AM, Kevin Sutter <kw...@gmail.com> wrote:

> The use of a qualified enum value should be valid for JPQL.  But, the spec
> doesn't seem to specify whether the enum type needs to be in it's own file
> or not.  I've looked through the spec and some references and they all seem
> to assume that these enums are defined in it's file and not embedded within
> the Entity definition.
>
> I'd be hard pressed to consider this a bug.  Maybe a feature request, but
> not a bug.  As you mentioned, if you define this enum separately,
> everything works as expected, right?  Is there some reason why that
> approach can't be done?
>
> Kevin
>
>
>
> On Sat, Jan 4, 2014 at 4:50 PM, twelveeighty <twelve.eighty@gmail.com
> >wrote:
>
> > Can someone confirm whether or not this is a known issue, or if this is a
> > known limitation?
> > When I define an  enum as part of my entity class, I am not able to use
> its
> > values as literals in a JPQL statement:
> >
> > package com.myorg.jpa;
> > public Foo {
> >         public enum FooType { FOO, BAR }
> >         @Enumerated(EnumType.STRING)
> >         private FooType type;
> > }
> >
> > select f from Foo f where f.type = com.myorg.jpa.Foo.FooType.BAR
> >
> > Error message: Attempt to query field "com.myorg.jpa.Foo.FooType.BAR"
> from
> > non-entity variable "com". Perhaps you forgot to prefix the path in
> > question
> > with an identification variable from your FROM clause?
> >
> > My version: OpenJPA 2.3.0-nonfinal-1540826
> >
> > However, if I take FooType and define it as its own Enum class
> > (com.myorg.jpa.FooType) the literal com.myorg.jpa.FooType.BAR works as
> > expected.
> >
> > Should I log a bug for this?
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://openjpa.208410.n2.nabble.com/Inner-enum-cannot-be-used-as-literal-in-JPQL-tp7585806.html
> > Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >
>



-- 
*Rick Curtis*

Re: Inner enum cannot be used as literal in JPQL

Posted by Kevin Sutter <kw...@gmail.com>.
The use of a qualified enum value should be valid for JPQL.  But, the spec
doesn't seem to specify whether the enum type needs to be in it's own file
or not.  I've looked through the spec and some references and they all seem
to assume that these enums are defined in it's file and not embedded within
the Entity definition.

I'd be hard pressed to consider this a bug.  Maybe a feature request, but
not a bug.  As you mentioned, if you define this enum separately,
everything works as expected, right?  Is there some reason why that
approach can't be done?

Kevin



On Sat, Jan 4, 2014 at 4:50 PM, twelveeighty <tw...@gmail.com>wrote:

> Can someone confirm whether or not this is a known issue, or if this is a
> known limitation?
> When I define an  enum as part of my entity class, I am not able to use its
> values as literals in a JPQL statement:
>
> package com.myorg.jpa;
> public Foo {
>         public enum FooType { FOO, BAR }
>         @Enumerated(EnumType.STRING)
>         private FooType type;
> }
>
> select f from Foo f where f.type = com.myorg.jpa.Foo.FooType.BAR
>
> Error message: Attempt to query field "com.myorg.jpa.Foo.FooType.BAR" from
> non-entity variable "com". Perhaps you forgot to prefix the path in
> question
> with an identification variable from your FROM clause?
>
> My version: OpenJPA 2.3.0-nonfinal-1540826
>
> However, if I take FooType and define it as its own Enum class
> (com.myorg.jpa.FooType) the literal com.myorg.jpa.FooType.BAR works as
> expected.
>
> Should I log a bug for this?
>
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Inner-enum-cannot-be-used-as-literal-in-JPQL-tp7585806.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>