@Entity
public class Store {}
@Entity
@Table(name = "storeitem")
public class StoreItem {
@Id @Column
private Integer storeId;
@Id
@ManyToOne @JoinColumn (name="productId", referencedColumnName="id")
private Product product;
@Column private Double cost;
}
mysql> desc storeitem;
+-------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------------+------+-----+---------+-------+
| StoreId | int(10) unsigned | NO | PRI | 0 | |
| ProductId | bigint(20) unsigned | NO | PRI | 0 | |
| cost | double unsigned | NO | | 0 | |
@Entity
@Table(name = "product")
public class Product {
@Id @GeneratedValue @Column(name = "Id")
private Long id;
@Column(name = "Name")
private String name;
}
mysql> desc product;
+-------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------------+------+-----+---------+----------------+
| Id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| Name | varchar(70) | NO | | | |
Criteria cr=sess.createCriteria(StoreItem.class);
cr.add(Restrictions.eq("product.name","butter"));
cr.list();
Когда я пытаюсь отфильтровать по свойству ребенка, я получаю это исключение ниже
org.hibernate.QueryException: could not resolve property: product.name of:StoreItem