Ganesh Java
Ganesh Java

Reputation: 47

JPA @query is not working when date value is null during insert

I have written below java code in my JPA repository.

@Query("insert into table (date_colum) value(:dateValue)",nativeQuery= true)
public int insertData(@Param("dateValue") dateValue);

Above code is working perfect when dateValue column is having some value. But when value of dateValue cloumn is null in that case it will giving the below error .

Error : ora-00932 inconsistent datatypes expected date got binary

Any solution please , help is appreciate.

Thanks in advance

Upvotes: 1

Views: 1823

Answers (1)

Ganesh Java
Ganesh Java

Reputation: 47

If We add @Temporal to your Date parameter, Spring Data knows how to present that parameter to Hibernate, even if it is null:

The code is like as below.

@Query("insert into table (date_colum) value(:dateValue)",nativeQuery= true)
public int insertData(@Param("dateValue") @Temporal java.util.Date dateValue);

Upvotes: 1

Related Questions