Hello,
I have the following classes.
MenuItem.javaCode:
@Entity
@Table(name = "VIEW_MENU_ITEM")
public class MenuItem {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@Column(nullable=false,name = "ITEM_LABEL")
private String label;
@Column(nullable=false,name = "TARGET")
private String target;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PARENT_ID")
@Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
private MenuItem parent;
@ManyToOne
@JoinColumn(nullable=false,name = "CATEGORY_ID")
private MenuCategory category;
@Type(type="yes_no")
@Column(length=1,name="IS_DEFAULT_ITEM")
private boolean isDefault;
..getters
MenuCategory.javaCode:
@SuppressWarnings("serial")
@Entity
@Table(name = "VIEW_MENU_CATEGORY")
public class MenuCategory implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@Column(nullable=false,name = "CATEGORY_LABEL")
private String label;
@Column(nullable=false,name = "CATEGORY_KEY")
private String key;
..getters
And when i create such a criteria query it doesnt work(says could not resolve property: category.key of: tr.domain.view.MenuItem)
Code:
return session.createCriteria(MenuItem.class)
.add(Restrictions.eq("category.key", category)).list();
But the following criteria query works.
Code:
return session.createCriteria(MenuItem.class).createAlias("category","category1")
.add(Restrictions.eq("category1.key", category)).list();
I dont want to create alias all the time.So what can i do to make the first query work?