Sunday 15 February 2015

java - Hibernate Criteria with Projections.groupProperty cannot return full hibernate object (ClassCastException) -


I'm relatively new to hibernate and there is a problem adding "separate" restrictions to my hibernate class.

  @Entity Public Category Tagged Offer {Private Long Tag_offers_id; Private string brand; Private long CID; Personal date created_data; // Getter and Setter and more fields}   

Earlier, we were creating a hibernate query as follows:

  Public Detected Works in Build (Last Tag Offer request made) {different taxonomic criteria = Separated Ceritaries. Forbes (Tagged off class); Criterion Add (restriction. Eq ("brand", request.getBrand ())); Criterion Add (restrictions. ("Cid", request.getCids ())); // Sorted by date criteria. AddOrder (property.forName ("createdDate"). Desc ()); Return criteria; }   

This will create the following (working) HQL query:

  Select this_tagged_offers_id as Tag 1_2_3_, this_.brand as brand2_3_, this_ Cid as Cid2_3_, created in this_.created_date form 6_2_3_ site.tagged_offers this_ where this_.brand =? And this_.country_code =? And in this_.cid (?,?) The order by the _.created_date desc border?   

Here comes the tricky part. Now we need to ensure that the results are given which are different on the 'CID' field. Meaning, return as many results as possible, a specific CID can be made available in each record.

I saw it in SQL, and it seems that the easiest way to do this is to simply hibernate in a 'group by CID' query, in terms of norms, what I basically do Trying to:

  Creating a Public Separation Classification (Last Tagged Offer Request) {Separate Criteria Criteria = Different Classification. Class (tagged operator. Square); Criterion Add (restriction. Eq ("brand", request.getBrand ())); Criterion Add (restrictions. ("Cid", request.getCids ())); // Sorted by date criteria. AddOrder (property.forName ("createdDate"). Desc ()); // ** new ** different criteria criteria .Setprogication (projection groupProperty ("cid")); Return criteria; } It creates almost the HQ that I am looking for, but later it throws a class cast exception (because it opposes Sid field contrary to the whole object). .  
  Select this YouTube as site0agged_offers as y0_, where it_.brand =? And this_.country_code =? And in this_.cid (?,?) And tagtype1_.tag_type =? This_med_date desc limit by this_.cid command by group?   

And the exception:

  java.lang.ClassCastException: java.lang.Long can not be put on com.mycompany.site.taggedoffers.dao .   

By any idea how can I use projections to work my way Am I

Get estimates for all the columns you need.

  launch list projection list = projection Projection list (); ProjectionList.add (Projections.groupProperty ("CID")); ProjectionList.add (Projections.property ("tagged_offers_id")); ... Criteria. Launch (projection list);    

No comments:

Post a Comment