-->
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: DetachedCriteria, Projections.Property & Restrictions.like
PostPosted: Thu Aug 02, 2012 4:54 am 
Newbie

Joined: Thu Aug 02, 2012 4:43 am
Posts: 1
I am trying to retrieve a list of events, returning only specific column name with filtering restrictions on certain column.
Therefore, I am utilizing Projections.property and Restrictions.like

I am trying to return event of activity like '%ball%' and venue like '%stadium%'.
Following are my mapping classes, hibernate call as well as the error message.

It seems that Hibernate is unable to identify the venue column.
If I remove "criteria.add(Restrictions.like("venue","stadium", MatchMode.ANYWHERE));"
or
If I remove ProjectionList pl = Projections.projectionList();,
, I will be able to get result.

Could someone kindly advise the what went wrong. Thanks in advance.

// Classes ==================
public class Event {
private Long eventId;
private Activity activity;
private Date startTime;
private String venue;
private String additional;
}

public class Activity {
private Long activityId;
private String activityName;
}

// Hibernate Method =====================
public List getEventList()
{
DetachedCriteria criteria = DetachedCriteria.forClass(Event.class);

// define fields to return
ProjectionList pl = Projections.projectionList();
pl.add(Projections.property("eventId").as("eventId"));
pl.add(Projections.property("activity").as("activity"));
pl.add(Projections.property("startTime").as("startTime"));
pl.add(Projections.property("venue").as("venue"));
criteria.setProjection(pl).setResultTransformer(new AliasToBeanResultTransformer(Event.class));

// join class
criteria.createAlias("activity","activity");

// filter restrictions
criteria.add(Restrictions.like("activity.activityName","ball", MatchMode.ANYWHERE));
criteria.add(Restrictions.like("venue","stadium", MatchMode.ANYWHERE));

return getHibernateTemplate().findByCriteria(criteria);
}

// Error ==========================
Hibernate: select this_.eventId as y0_, this_.activityId as y1_, this_.startDateTime as y2_, this_.venue as y3_ from Event this_ inner join Activity ac1_ on this_.activityId=ac1_.activityId where y3_ like ?

Root cause of ServletException.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
...
org.hibernate.exception.SQLGrammarException: could not execute query
..
java.sql.SQLException: [BEA][SQLServer JDBC Driver][SQLServer]Invalid column name 'y3_'.


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.