CONSULTAS JPQL CON INNER JOIN JPA

Que tal amigos por favor tengo esta consulta y me funciona excelente: Donde actualmente en la clase ProductImage Tengo un @ManyToOne y el constructor con parámetros , mi pregunta es ¿Cómo puedo hacer el INNER JOIN y traer campos de otro POJO o Clase que no está dentro de mi clase ProductImage?

public ProductImage(Long id, String nameImgCloudinary, String imageUrlCloudinary, String imageIdCloudinary,
        Boolean principal, DataState state, Long idProduct, String referenceProduct, String marca, String title,
        String description, String nota, BigDecimal longitud, BigDecimal width, BigDecimal height,
        BigDecimal weight, BigDecimal minimumSale, String sku, String barcode, Integer deliveryTime,
        Boolean includeTransportation, LocalDateTime dateRegister) {
    this.id = id;
    this.nameImgCloudinary = nameImgCloudinary;
    this.imageUrlCloudinary = imageUrlCloudinary;
    this.imageIdCloudinary = imageIdCloudinary;
    this.principal = principal;
    this.state = state;
    this.product = new Product(idProduct, referenceProduct, marca, title, description, nota, longitud, width,
            height, weight, minimumSale, sku, barcode, deliveryTime, includeTransportation, dateRegister);
}

@ManyToOne
@JoinColumn(name = "id_producto", nullable = true, referencedColumnName = "id", foreignKey = @ForeignKey(name = "FK_producto_imagen_Producto_id"))
private Product product;


@Query("SELECT NEW ProductImage ("
        + "pi.id,"
        + "pi.nameImgCloudinary,"
        + "pi.imageUrlCloudinary,"
        + "pi.imageIdCloudinary,"
        + "pi.principal,"
        + "pi.state,"
        + "prod.id,"
        + "prod.referenceProduct,"
        + "prod.marca,"
        + "prod.title,"
        + "TRIM(LOWER(prod.description)),"
        + "prod.nota,"
        + "prod.longitud,"
        + "prod.width,"
        + "prod.height,"
        + "prod.weight,"
        + "prod.minimumSale,"
        + "prod.sku,"
        + "prod.barcode,"
        + "prod.deliveryTime,"
        + "prod.includeTransportation,"
        + "prod.dateRegister) FROM ProductImage pi "
        + "JOIN pi.product prod "
        + "WHERE pi.principal=true AND pi.state.active=true AND pi.state.enable=true "
        + "ORDER BY prod.dateRegister DESC")
public List<ProductImage> findAllTopProductImagelient(Pageable pageable);


Read more here: https://stackoverflow.com/questions/67377501/consultas-jpql-con-inner-join-jpa

Content Attribution

This content was originally published by vianey vargas at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: