• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

I get a ClassCastException

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Learning how to use Hibernate Criteria, i get the following error



here ->


Pojo ->


Probably complaining about casting Object to TestRank? but this works



???
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use Projections this way your result will be a List of arrays of Objects, not a List of POJOs. Given you have all the properties you are Projecting already in your POJO I don't see what benefit using Projections is giving you here. What is it you are trying to achieve?
 
Songezo Nkukwana
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:If you use Projections this way your result will be a List of arrays of Objects, not a List of POJOs. Given you have all the properties you are Projecting already in your POJO I don't see what benefit using Projections is giving you here. What is it you are trying to achieve?



If you don;t mind could you please explain the use of projections.property? I'm new to hibernate and busy using examples but some are not clear enough ... Thanks Paul
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might use Projections to query for properties not on the object you are querying, for example a derived property (thing average, maximum etc.) Or you might use them to create a new, unmapped object at runtime. If all you are doing is returning the properties of an already mapped object then you don't need to use them.
 
Songezo Nkukwana
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:You might use Projections to query for properties not on the object you are querying, for example a derived property (thing average, maximum etc.) Or you might use them to create a new, unmapped object at runtime. If all you are doing is returning the properties of an already mapped object then you don't need to use them.



How should i interpret the following 'incomplete' queries?



Perhaps am trying to figure which should i use for one to many relationship?
 
Songezo Nkukwana
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In fact Paul, looking at the POJO i posted, how would i write a Criteria query to get all RankProfiles with a specified id? Note that RankProfile has a many to one Rank relationship, so a Rank can be associated with many RankProfiles ... I think given such examples, i may be set to begin coding my Criterion queries
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you might do is add another criterion on rankProfiles that matches on id. Have a look at this for an example.
 
Songezo Nkukwana
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried these two methods




Both seem to work, which one is recommended? Would they work for lazy-initialization/loading?
reply
    Bookmark Topic Watch Topic
  • New Topic