Is there any restriction on hibernate to perform query using inheritance?

0

Good morning / afternoon / evening gentlemen.

The situation is as follows. I have a query that performs the registration of child entities in order to divide the object. But in a future moment the list is displayed. This data is not all contained in the object. They are even limited by pagination. After the paging search is only being returned to me the child object saved in the database. When I clearly need the parent object, with the very limited fields as defined in the inheritance.

This problem has not seemed to have an appropriate code-level solution (not that I know of) so I need your help. You may have encountered similar problems. And I believe this is a more elegant way than writing a sql query to get only the fields I want.

The object I do not want to display or return that is most vital is an entity that is an attribute of the parent class. This entity contains several other fields (not shown in the list screen) and other entities that are cascaded by hibernate.

Thank you in advance.

The code is as simple as you can imagine. Only two classes a daughter with all fields and one parent only with, however as the colleague asked I will post sample codes.

Come on:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Pai{
    @Id
    @GeneratedValue
    public Long id
    private String gene.
    //get's e Set's.
}

@Entity
public class Filho extend Pai{
    @Id
    @GeneratedValue
    public Long id
    private String personalidade;
    //get's e Set's
}

public intervace PaiRepository extend JPARepository<Pai, Long>{
}
public intervace FilhoRepository extend JPARepository<Filho, Long>{
}

Queries are done using paiRepository.findAll(Pageable page); and parent_repository are instances of the above interfaces.

Any more questions about the problem just ask. I'm new here and you can see the points. But by the rhythm of the negative. So just ask. As you can see the code is simple. The problem that when I search with the parent repository comes as if it were the child. With all the data. Which is what I want to avoid. Since it would consume data in return and show data more than it should be a security flaw.

    
asked by anonymous 21.02.2018 / 02:29

0 answers