Reputation: 513
Let say I have two entity classes in play framework, java:
@Entity
public class User extends Model implements Validation {
@Id
private String email;
private String password;
@OneToOne
@PrimaryKeyJoinColumn(referencedColumnName = "userEmail")
private Address address;}
and
@Entity
public class Address extends Model{
@Id
@Column(name="userEmail")
private String email;
private String streetName;
private String city;
private String country;}
Now I want to retrieve all users from database and sort them based on streetName property of Address model. I used this List<Restaurant> list = Restaurant.find.order("streetName asc").findList();
but I get following error:
[PersistenceException: Query threw SQLException:Unknown column 'streetName' in 'order clause'
Bind values:[]
If I put any User property as order string (...order("email asc").findList();
) it works and I get ordered list, but how can I make it order Users based on Address properties?
Upvotes: 0
Views: 106
Reputation: 101
Try Restaurant.find.order("address.streetName asc").findList()
Upvotes: 2