Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA 2.0 specifying type of null-valued parameter  RSS feed

martin mucha
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have to call some DB function. When I need to do that some time ago, I did that via NamedNativeQuery. Something like this
select fn(:FIRST_PAR, :SECOND_PAR) from dual;

Question one: is there a better way, than defining it as (named)native query ,to do that(not calling that function is not a possibility)? I did not found better way.

If not, lets continue.
That function has some specific type of arguments. But those arguments are nullable. When using setParameter(String, Object) bad argument type will be determined and used. In JPA 1.0 I did this: got javax.persistence.Query, unwraped org.hibernate.Query from it which has three argument version of setParameter, where the last one can specify type of null valued parameter -- for example org.hibernate.type.LongType

Is there a better way how to do it in JPA 2.0? I've found setParameter(Parameter<T>, T) method, but in javadoc is mentioned that this method should be used for Criteria queries only.

Do you have any recomendations how to solve this?

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!