Home > Software engineering >  Hibernate 6 / JPA - how to update smallint column with fixed value?
Hibernate 6 / JPA - how to update smallint column with fixed value?

Time:12-23

I have an update that works like this:

@Modifying
@Query("update Entity set smallintCol = 1 where id = :id")
void doUpdate(@Param("id") int id)

When upgrading to Hibernate 6.1 thru Spring Boot 3, validation fails for this query because 1 is integer and the column is short.

This doesn't work:

@Modifying
@Query("update Entity set smallintCol = ((short) 1) where id = :id")
void doUpdate(@Param("id") int id)

How would I do this update?

Edit:

I am using PosgreSQL

The error that is issued is when booting spring:

Caused by: org.hibernate.query.SemanticException: The assignment expression type [java.lang.Integer] did not match the assignment path type [java.lang.Short] for the path [alias_861886687.qtTentativasEnvio] 

Column is mapped as:

@Column(name = "qt_tentativas_envio", nullable = false)
private short qtTentativasEnvio;

CodePudding user response:

Have you tried?

@Query("update Entity set smallintCol = cast(1 as short) where id = :id")
  • Related