Let's suppose we have the hibernate entities User
and Post
. A user can have many posts.
Suppose we are never going to get the user with their posts; we always only are going to need to get the list of posts that belong to a user, but without the user info.
In this case, it's necessary to have in the entity Post
an attribute with type User with the annotation @ManyToOne?
Or is it valid to have just an attribute userid type Integer? This way the jpql query would be like:
select p from Post p where p.userid = :userid