Error: 'Operand type clash: image is incompatible with numeric'

0

When trying to save an object in the database, it gives the following exception:

  

org.hibernate.exception.DataException: could not update. [...] Caused by: java.sql.SQLException: Operand type clash: image is incompatible with numeric.

I got the query run by Hibernate to do directly in the database. I put in it the same values that were being given in the code. Only the date (which in code is assigned with Calendar.getInstance() ) I did not write, putting a GETDATE() . It worked! If all the fields I wrote the same, only the date that was obtained otherwise, I believe the problem is on the date. Even more by 'org.hibernate.exception.DataException'.

Now, I do not understand why. The field type in the database is datetime . In JPA, in the code, it is as @Temporal(TemporalType.TIMESTAMP) . Calendar.getInstance() should not be a problem then.

Furthermore, you still have this

  

'Operand type clash: image is incompatible with numeric'.

Is it like he's accusing me of putting something of an image into the object? What's more, it says it's incompatible with numeric? But the field is dated. And the other fields should be ok as it worked when I query with the same values straight into the database.

UPDATED:

The query that is generated by hibernate:

update TABELA 
set DATA_ALTERACAO_D= ?, 
LOGIN_USUARIO_T= ?, 
FK_TABELA2 = ?, 
IND_T= ?, 
LOGIN_USUARIO_ALT_T= ?, 
NUM_A = ?, 
NUM_U = ?, 
FK_TABELA2 = ?, 
S = ? 
where ID = ?

I placed the query directly in the database, with the same values that would be received placed in the query in the application, replacing only the date (which in the application was Calendar.getInstance() ) and put GETDATE() of SQL. ex:

update TABELA 
set DATA_ALTERACAO_D= GETDATE(), 
LOGIN_USUARIO_T= '8888888', 
FK_TABELA2 = '123123123123', 
IND_T= 'I', 
LOGIN_USUARIO_ALT_T= '8888888', 
NUM_A = '654654', 
NUM_U = '456456', 
FK_TABELA2 = '38383838', 
S = '1' 
where ID = '7777777777'

There it worked. That is, the problem must be in the date field. But I can not understand how date relates to this error message.

    
asked by anonymous 18.11.2015 / 12:19

1 answer

0

It seems that it was because it was a field that was fk (so I did not just pass the ID, I passed the whole object to that fk field) but in jpa it was set as common field (@Column) and not as fk (@JoinColumn ). Because it was configured as a common field, it expected only pure value (I think it would work if I just passed the pure id), but I would pass an entire object, from which it should get the id and it should not be understood. It would only work if the field was set to be fk, with @JoinColumn.

I switched to @JoinColumn and it worked

    
26.11.2015 / 19:35