假设我在play框架中有两个实体类,java:
@Entity
public class User extends Model implements Validation {
@Id
private String email;
private String password;
@OneToOne
@PrimaryKeyJoinColumn(referencedColumnName = "userEmail")
private Address address;}
和
@Entity
public class Address extends Model{
@Id
@Column(name="userEmail")
private String email;
private String streetName;
private String city;
private String country;}
现在我想从数据库中检索所有用户,并根据Address model的streetName属性对它们进行排序。我使用了List<Restaurant> list = Restaurant.find.order("streetName asc").findList();
但我收到以下错误:
[PersistenceException: Query threw SQLException:Unknown column 'streetName' in 'order clause'
Bind values:[]
如果我将任何用户属性作为订单字符串(...order("email asc").findList();
),它可以工作,我得到有序列表,但是如何根据地址属性对其进行订购?
答案 0 :(得分:2)
尝试Restaurant.find.order("address.streetName asc").findList()