-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem using enums with setParameter in native queries
PostPosted: Thu Mar 06, 2008 11:35 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 1:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate cannot parse the SQL query and guess the enum you are targetting, so it does not know if you want an ordinal or string persisted enum

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.