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 of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.