Jpaupdateclause with Join

Asked

Viewed 96 times

1

I have the following entities:

@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(schema = "MYDB", name = "TB_TESTE")
public class Teste implements Serializable {

    @ManyToOne
    @JoinColumn(name = "CO_TIPO_TESTE")
    private TipoTeste tbTipoTeste;

    @Column(name = "ST_REGISTRO_ATIVO")
    private String stRegistro;

}

@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(schema = "MYDB", name = "TB_TIPO_TESTE")
public class TipoTeste implements Serializable {

     @Column(name = "TP_ARQUIVO")
     private String tpArquivo;

}

I need to update the Test table based on an attribute from another table. I expected the following code to generate an update with Join.

JPAUpdateClause update = new JPAUpdateClause(em, QTeste.teste); update.where(QTeste.teste.tbTipoTeste().tpArquivo.eq("X")); update.set(QTeste.teste.stRegistro, 'N'); update.execute();

However, the following SQL was generated:

update MYDB.TB_TESTE cross join set ST_REGISTRO=? where TP_ARQUIVO=?

The generated SQL has only one of the tables needed to do Join, and when executed gives the error ORA-00971: SET keyword not found. There is how to do Join in the update otherwise?

  • Hello! I didn’t quite understand the question, could you explain it better? What I didn’t understand was the part "I need to update the Test table based on an attribute from another table", you want to copy the attributes of all rows from one table to the other, that’s it?

  • Hello! The Test table has a reference to the Typoteste table. In Typoteste, I have the Tpfile column. I need to set, in the Test table, the Stregistro column to 'N' as long as the Test Tpfile is 'X'. Since Tpfile is in Typethis, I referred to it as "an attribute from another table". I even managed to query it, only I needed to use a subquery. Is there any way to do this just by using a Join in the update?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.