-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteria doesnt work without Alias
PostPosted: Tue Mar 30, 2010 3:33 am 
Newbie

Joined: Tue Mar 30, 2010 3:22 am
Posts: 2
Hello,
I have the following classes.


MenuItem.java

Code:
@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.java
Code:
@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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.