Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1074947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:12:21+00:00 2026-05-16T21:12:21+00:00

Can JPQL execute LIKE expressions against enums? If I have an entity Foo with

  • 0

Can JPQL execute LIKE expressions against enums?

If I have an entity Foo with an enum field bar I can execute the following in MySQL(bar is stored as a MySQL enum)…

SELECT * FROM Foo WHERE `bar` LIKE '%SUFFIX'

However, the corresponding query in JPQL…

SELECT f FROM Foo f WHERE f.bar LIKE '%SUFFIX'

…complains that…

Parameter value [%SUFFIX] was not matching type [com.example.Foo$EnumType] 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:12:21+00:00Added an answer on May 16, 2026 at 9:12 pm

    I don’t think it’s possible, the left part of a LIKE is supposed to be a string_expression (in standard JPA). From the specification:

    4.6.9 Like Expressions

    The syntax for the use of the
    comparison operator [NOT] LIKE in a
    conditional expression is as follows:

    string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]
    

    The string_expression must have a
    string value. The pattern_value is
    a string literal or a string-valued
    input parameter in which an underscore
    (_) stands for any single character,
    a percent (%) character stands for any
    sequence of characters (including the
    empty sequence), and all other
    characters stand for themselves. The
    optional escape_character is a
    single-character string literal or a
    character-valued input parameter
    (i.e., char or Character) and is
    used to escape the special meaning of
    the underscore and percent characters
    in pattern_value.

    And an enum_expression is not a string_expression.

    The following would work though (using enum literals):

    SELECT f 
      FROM Foo f 
     WHERE f.bar = com.acme.Bar.SOME_CONSTANT 
        OR f.bar = com.acme.Bar.SOME_OTHER_CONSTANT
    

    Another option would be to actually store the bar field as a String (and to do some conversion from and to an enum in the getter/setter).

    Reference

    • JPA 1.0 Specification
      • Section 4.6.9 “Like Expressions”
      • Section 4.14 “BNF”
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPA object which has a many-to-many relationship like this: @Entity public
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) I have a Rails
Can anyone tell me how I can display a status message like 12 seconds
Let's say I have the following tables my_profile_data ------------- integer: my_profile_data_id integer: profile_id integer:
I thought I know how to use JOIN in JPQL but apparently not. Can
Can I use the following across all browsers? <a href=# onclick=doSomething()>Click here.</a> Is this
Can anyone tell me what's wrong with this robots.txt? http://bizup.cloudapp.net/robots.txt The following is the
Can I connect to a Ubuntu server, that is running MySQL using ADO.NET or
I need to solve the following question which i can't get to work by
If all tables I want to delete from have the column gamer_id can i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.