I have created a JPA query to obtain a set of data. What it returns is an entity and a new field (an extra column) in each of the records.
@Query(value = "C.id_transaccion as transacionId, SELECT A.* FROM (modulos A RIGHT JOIN modulos2 B ON A.uu_id_modulo = B.uu_id_modulo) LEFT JOIN operacion C ON B.id_operacion = C.uu_id_operacion WHERE uu_id = ( :uudId)", nativeQuery = true)
List<Module> queryModules(@Param("uu_id") Integer uuId);
Which through JPA
my object is filled correctly but, the extra field 'transacionId
' always returns null
. Why? I have tried if it was a problem of the name that I have given it but it is not.
My Entity
:
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class Module {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer uuIdModule;
private Integer transacionId;
}
Is the problem that transacionId
is not a column? Then, does not belong to 'Module' entity, and it is not able to map it?
Finally, I used JPA-Projections to resolve it. Its an interface with the attributes name prefixed by 'get'.
public interface ModuleProjection {
Integer getTransactionId();
}