Is there a problem with using enums with setParameter in native queries?
I had a query that worked fine as a JPA query and returned some data. When I was forced to make it SQL Server specific to use a "nolock" hint, running the query failed to produce any results, even though there was data in the table.
Code:
String sql = "SELECT foo.* FROM my_table foo (nolock) WHERE foo.bar = :bar"
Query query = cpdsEntityManager.createNativeQuery(sql, Foo.class);
query.setParameter("bar", MyEnum.BAR);
List<Foo> results = query.getResultList();
If I change the bound parameter to a String, it works fine:
query.setParameter("bar", MyEnum.BAR.toString();
So it looks like setParameter isn't handling the enum properly.
We're using JBoss 4.2.0 / Hibernate 3.2.3.ga