Skip to content

Closed Projection does not work with @EntityGraph [DATAJPA-1501] #1814

Open
@spring-projects-issues

Description

@spring-projects-issues

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)

Metadata

Metadata

Assignees

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions