1
Good morning/afternoon/evening Gentlemen.
The situation is as follows. I have a query that performs the registration of daughter entities aiming to divide the object. However at a future time the list is displayed. This data is not all contained in the object. It is even limited by paging. After the pagination search is only being returned to me the child object saved in the bank. When I clearly need the parent object, with the fields well limited as it was defined in inheritance.
This problem has not seemed to me to have an appropriate solution at code level (not that I know of) so I need your help. It’s likely you’ve encountered similar problems. And I believe this is a more elegant way than writing an sql query to get only the fields I want.
The object that 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 on the list screen) and including other entities that are cascaded by Hibernate.
Thanks in advance.
The code is as simple as you can imagine. Only two classes a daughter with all fields and a father with only, but as the colleague asked I will post codes examples.
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 made using paiRepository.findAll(Pageable page);
and paiRepository are instances of the above interfaces.
Any more questions about the problem just ask. I’m new here and you see by the dots. But by the pace of the negative. So just ask. As you can see the code is simple. The problem that when I search with the parent Pository comes as if it were the child. With all the data. Which is what I want to avoid. Since it would consume data on return and show more data than it should be a security breach.
Post your code.
– alxwca
And you Negative for this? Wow. Cool...
– Andersoney Rodrigues
What is the inheritance strategy?
@Inheritance(strategy=
... When you search for your child and make afilho.getGene()
, returns null?– Dherik
No. The gene goes(Comes the value of the database). All father and son data go. The problem is this. I just want the father’s, right now the son’s data is not important.
– Andersoney Rodrigues