-->
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.  [ 2 posts ] 
Author Message
 Post subject: Getting exception while running criteria query in other way
PostPosted: Thu Apr 23, 2015 3:14 am 
Newbie

Joined: Thu Apr 23, 2015 2:57 am
Posts: 1
Hi All

order.java:-------------------------------------------------------------------------
private int id;
private Date Date;
private int amount;
private customer customer;

@ManyToOne
@JoinColumn(name="customer_id")
public customer getCustomer() {
return customer;
}
public void setCustomer(customer customer) {
this.customer = customer;
}
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Date getDate() {
return Date;
}

customer.java-------------------------------------------------------------------------------------------------
private int id;
private String name;
private String address;
private int age,salary;
private List<orders> cus_orders;

@OneToMany(mappedBy = "customer",fetch = FetchType.EAGER)

public List<orders> getCus_orders() {
return cus_orders;
}
public void setCus_orders(List<orders> cus_orders) {
this.cus_orders = cus_orders;
}

@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {

FOLLOWING IS THE CODE THAT EXECUTES WITH NO EXCEPTION---------------------------------------------------------------

Criteria crit = session.createCriteria(orders.class).createAlias("customer", "cust").add(Restrictions.eq("amount",1500)).add(Restrictions.eq("cust.name","Kaushik"));
List list = crit.list();
Iterator<orders> itr = list.iterator();
while(itr.hasNext()){
System.out.println("---------------------->>>>>"+ (itr.next()).getCustomer().getName());
}

AND CHANGING THE CRITERIA QUERY OTHER WAY ,I AM GETTING EXCEPTION------------------------------------------
Criteria crit = session.createCriteria(customer.class).createAlias("orders", "ord).add(Restrictions.eq("name","Kaushik")).add(Restrictions.eq("ord.amount",1500));
List list = crit.list();

Here is the exception--------------------------------------------------------------------------------------------

Exception in thread "main" org.hibernate.QueryException: could not resolve property: orders of: Entity.customer
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1978)
at org.hibernate.loader.criteria.EntityCriteriaInfoProvider.getType(EntityCriteriaInfoProvider.java:57)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathInfo(CriteriaQueryTranslator.java:245)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:229)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:112)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:88)


Please Let me know why I cannot write the query the other way around (the highlighted way)
Waiting for your response

Varun Maheshwari


Top
 Profile  
 
 Post subject: Re: Getting exception while running criteria query in other way
PostPosted: Fri Apr 24, 2015 4:11 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
Quote:
could not resolve property: orders


The property is called cus_orders


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

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.