3
I have a question regarding table junctions ,I have a class sale the same has Customer,dTCompra,listProducts.I would like to make a report with the product name,customer name ,product value and purchase date only I don’t have the slightest idea how to do due to @Manytomany annotations creating an intermediate table.
Entity Venda
 @Entity
@XmlRootElement
public class Venda implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String dtCompra;
    @OneToMany
    private List<Produto>produtos;
    @ManyToOne
    private Cliente cliente ;
    public Venda() {
    }
    public Venda(String dtCompra, List<Produto> produtos, Cliente cliente) {
        this.dtCompra = dtCompra;
        this.produtos = produtos;
        this.cliente = cliente;
    }
    public String getDtCompra() {
        return dtCompra;
    }
    public void setDtCompra(String dtCompra) {
        this.dtCompra = dtCompra;
    }
    public List<Produto> getProdutos() {
        return produtos;
    }
    public void setProdutos(List<Produto> produtos) {
        this.produtos = produtos;
    }
    public Cliente getCliente() {
        return cliente;
    }
    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Venda)) {
            return false;
        }
        Venda other = (Venda) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
    @Override
    public String toString() {
        return "entidade.Venda[ id=" + id + " ]";
    }
}
Entity Produto :
    package entidade;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlRootElement;
/**
 *
 * @author 631520084
 */
    @Entity
    @XmlRootElement
    public class Produto implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE)
        private Long id;
        private float preco;
        private String nome;
        @ManyToMany
        private List<Fornecedor> fornecedor;
        @ManyToOne
        private Categoria categoria;
        public Produto(float preco, String nome,  List<Fornecedor> fornecedor, Categoria categoria) {
            this.preco = preco;
            this.nome = nome;
            this.fornecedor = fornecedor;
            this.categoria = categoria;
        }
        public Produto() {
        }
        public float getPreco() {
            return preco;
        }
        public void setPreco(float preco) {
            this.preco = preco;
        }
        public String getNome() {
            return nome;
        }
        public void setNome(String nome) {
            this.nome = nome;
        }
        public List<Fornecedor> getFornecedor() {
            return fornecedor;
        }
        public void setFornecedor(List<Fornecedor> fornecedor) {
            this.fornecedor = fornecedor;
        }
        public Categoria getCategoria() {
            return categoria;
        }
        public void setCategoria(Categoria categoria) {
            this.categoria = categoria;
        }
        public Long getId() {
            return id;
        }
        public void setId(Long id) {
            this.id = id;
        }
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        }
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Produto)) {
                return false;
            }
            Produto other = (Produto) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            }
            return true;
        }
        @Override
        public String toString() {
            return "entidade.Produto[ id=" + id + " ]";
        }
    }
Sale Business Layer (Where Join Goes)
package rn;
import entidade.Fornecedor;
import entidade.Produto;
import entidade.Venda;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import util.Conexao;
/**
 *
 * @author 631520084
 */
public class VendaRN {
    public List<Venda> imprimir() {
        Conexao con = new Conexao();
        EntityManager em = con.getEntidade();
        String jpql = "Select venda from Venda venda ";
        Query query = em.createQuery(jpql);
        List<Venda> listaVendas = query.getResultList();
        em.close();
        return (listaVendas);
    }
    public Venda inserir(Venda venda) {
        Conexao con = new Conexao();
        EntityManager em = con.getEntidade();
        em.getTransaction().begin();
        for (Produto produto : venda.getProdutos()) {
            em.merge(produto);
        }
        em.merge(venda.getCliente());
        em.persist(venda);
        em.getTransaction().commit();
        em.close();
        return venda;
    }
}
You can post some parts of the code?
– prmottajr
of course, already added
– Felipe Machado