1
I have a Product Entity-Class.
@Entity
public class Produto implements Serializable{
@Id
@GeneratedValue
private long id;
@Column(length = 70, nullable = false)
private String cod;
@Column(length = 100, nullable = false)
private String descricao;
@Column
@OneToOne
@JoinColumn(name = "idUnComer")
private Unidade unComer;//unidade comercial
}
However, when I query:
Select prod.id as id,prod.cod as cod,prod.descricao as descricao,prod.unComer as unComer from Produto prod
It does not list if there is no commercial unit saved.Bringing in the query only the values where the foreign key was filled.
If I do so:
from Produto
It lists all registrations, having foreign keys null or not.
Actually my Product, contains several other fields, only I wanted to list from the bank only a few that I need.
Someone’s been through it?
I am using Hibernate 4.3 and mysql 5.6.
Your
query
presents errors instacktrace
, publish in the question!? vc does not do theprod.descricao
and its entity does not possess the attributepartGer
.– Marcos Sousa
Does not generate errors. Simply does not list if you have null in relational attributes, such as business unit. To resolve I had to do left Join in the query, and when calling Prod.unComer it was already to do. It’s kind of redundant, but it was the solution I had to make
select prod.id as prod, prod.cod as cod, prod.descricao as descricao,prod.unComer as unComer from Produto prod left join prod.unComer as unComer
– Marlucio Pires
Marlucio Pires. Cool, just add the answer to close the question.
– Marcos Sousa