Binding a Java enum type to a native query parameter in Hibernate

Solution Verified - Updated -

Issue

  • A Java enumerated type (e.g. public enum Status { OFF, ON }) is bound to a native query parameter
Query qry = em.createNativeQuery("select ... from status_table where status = :status");
qry.setParameter("status", Status.ON);
  • The underlying type in the database is a character/string type
  • The query returns no results
  • The trace log with type tracing configured shows the binding as the string ON

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 4
    • 5
    • 6
  • Hibernate
    • 3
    • 4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content