JPA Native Query set null parameter

后端 未结 4 1563
迷失自我
迷失自我 2020-12-09 11:02

Here is my code part:

Query q = em.createNativeQuery(\"insert into table_name (value_one, value_two, value_three) values (?,?,?)\");
q.setParameter(1, value1         


        
4条回答
  •  鱼传尺愫
    2020-12-09 11:42

    I have faced the same issue when use EntityManager.createNamedQuery(guess the same issue with createNativeQuery).

    In case you are going to pass nullable parameter to Query then use TypedParameterValue which allows to pass the type.

    For instance:

    setParameter("paramName", new TypedParameterValue(StandardBasicTypes.LONG, paramValue));
    

    Here you explicitly set the type of passed value and when you pass null value as processor know the exact type.

提交回复
热议问题