Binding a Java enum type to a native query parameter in Hibernate
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.