Doubt Criteria

1

Can I create a critéria with an entity that is not mapped to another entity? Or do I have to use a native query to do this query?

I have a user entity and another product but I do not have product relationship with user but I have to bring the user name in the product query, whereas in the user there is only one variable idProduct without relationship.

Example:

   @Entity
    @Table(name = "DCF_USUARIOS")
    public class UsuarioTO{


            @Id
            @Column(name = "id")
            @GeneratedValue(strategy = GenerationType.AUTO)
            private Long id;

         @Column(name = "nome_usuario")
            private String nomeUsuario;


            @Column(name = "id_produto")
            private Long idProduto;
        }

        @Entity
        @Table(name = "DCF_PRODUTO")
        public class ProdutoTO{


            @Id
            @Column(name = "id")
            @GeneratedValue(strategy = GenerationType.AUTO)
            private Long  id;

        }

So I want to make a criteria in product, but I need to bring the name of the user that has the id of the product recorded in the entity being that they are not related to each other. I would like to do with criteria or I have to do a nativeQuery with Join between the two tables?

    
asked by anonymous 17.10.2017 / 17:16

0 answers