Reputation: 501
I two classes set up this way:
public class Listing extends Model {
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
public User user;
public String name;
}
public class User extends Model {
@Id
@Constraints.Required
@Formats.NonEmpty
public String username;
@OneToMany(mappedBy="user")
public List<Listing> listing;
}
The problem is that the query to return only the particular user's Listings does have a join in it as I would expect it to, but has something like:
select t0.name
from listing t0
where t0.user_id = '[email protected]'
Any idea of what am I doing wrong?
Upvotes: 1
Views: 991
Reputation: 7877
You need to define explicity the join in order to fetch elements from the Listing table.
In the User class :
find.fetch("listing").findList();
Upvotes: 2