java – How to map a column that does not exist in the database?

Question:

I have a little problem mapping (JPA) columns of a class on my system. I have some database procedures that do a lot of things already and I wouldn't want to stop using them, but I don't know how to map them.

SELECT r.*, ultimo_documento(r.id) as ultimo, ultima_acao(r.id) as ultima,
abcd(r.id, r.nome) as campo_teste
FROM requerimento

I have in my class the fields ' ultimo , ultima , campo_teste ' mapped with @Transient. But these fields are not filled. I use @NativeQueries declared before the entity.

How to map a column that does not exist in the database?

Answer:

query.addScalar("campo_teste", StringType.INSTANCE); // Ou seja lá qual for o tipo
query.list();

?

Scroll to Top