Open
Description
asfernandes opened DATAJPA-1501 and commented
I have entities that map others entities using @ManyToOne(fetch = FetchType.LAZY)
.
// Endereco.java
@Entity
@Table(name = "enderecos")
public class Endereco
{
private Integer codigo;
private Cidade cidade;
@Id
public Integer getCodigo()
{
return super.getCodigo();
}
public void setCodigo(Integer codigo)
{
this.codigo = codigo;
}
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "cid_codigo")
public Cidade getCidade()
{
return cidade;
}
public void setCidade(Cidade cidade)
{
this.cidade = cidade;
}
}
// Cidade.java
@Entity
@Table(name = "cidades")
public class Cidade
{
private Integer codigo;
private String nome;
@Id
public Integer getCodigo()
{
return super.getCodigo();
}
public void setCodigo(Integer codigo)
{
this.codigo = codigo;
}
public String getNome()
{
return nome;
}
public void setNome(String nome)
{
this.nome = nome;
}
}
Then I have created a repository interface with a method using @EntityGraph
:
@EntityGraph(type = EntityGraphType.FETCH,
attributePaths = {
"cidade"
}
)
<T> List<T> findFetchCidade(Class<T> type);
And created projection interfaces:
public interface EnderecoProjection
{
Integer getCodigo();
CidadeProjection getCidade();
/*
@Value("#{target.codigo}")
Integer getSomething();
*/
}
public interface CidadeProjection
{
Integer getCodigo();
String getNome();
}
When I use findFetchCidade passing a EnderecoProjection, I have this error:
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
Note that if I uncomment the @Value
annotation, the projection becomes opened and then no error happens
Affects: 2.1.4 (Lovelace SR4)