-->
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.  [ 8 posts ] 
Author Message
 Post subject: Wrapping selected object properties and ...
PostPosted: Fri Nov 18, 2005 1:48 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
I use the following amazon.com book review example to illustrate my question.
Code:
class Book {
private String titile;
private Author auther;
private String description;
//...
private Set<Review> reviews;
}

Code:
class Auther {
private String fullName;
//...
}

Code:
class Review {
private String comment;
private Short rating;
private Calendar postDate;
//...
}

Now, I need to retrieve a list of book by either searching or subject for view only. I only want to have the following information in the list.
    title
    auther's name
    descrption
    # of reviews
    the average rating
    the last review time

The above are the properties of a Book object or the properties of its child classes, Auther and Review, and some calculation results of properties.

My question is not about how to write the HQL. There are plenty such examples in the reference documentation. My question is how to wrap all these data into an object or I don't really need to care about it. No object type is explicit stated in the front end, on a JSP file. I have used a data transfer object for a single object properties case. Using a transfer object requests a Hibernate mapping: property -> table column. I can't see how a mapping can take place in this sample.

I have done an extended research, but haven't found any related information. Can someone point me the direction please?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 3:12 pm 
Beginner
Beginner

Joined: Tue Feb 01, 2005 5:26 pm
Posts: 24
Location: dallas
Use HQL something like this.

Code:
Query select = session.createQuery("select new YourOwnObject(b.title,b.author.name,count(b.reviews),avg(b.reviews.ratings)) from Book b");


HQL returns a list of YourOwnObject's.

if this post helps you, dont forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 4:04 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
Thanks for your reply.

What about the last review time & date?

Also, how you let Hibernate know the definition of the YourOwnObject? What your mappling file looks like?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 4:46 pm 
Beginner
Beginner

Joined: Tue Feb 01, 2005 5:26 pm
Posts: 24
Location: dallas
you can use max function like max(b.reviews.postDate)
your own object is simply a POJO, i dont think it needs to have any hibernate mapping file.

if it helps, dont forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 1:03 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
sreepraveen_2000 wrote:
your own object is simply a POJO, i dont think it needs to have any hibernate mapping file.


Thanks again for your information. My question is not about how to write the HQL, but how to let Hibernate know the transfer object class as what I stated clearly in my original question. My understanding is that Hiberante needs to know any classes appeared in HQLs and the only way to let Hibernate know a class definition is to have a class mapping file. If it is not in a mapping file, a Hibernate query exception will occur.

Code:
org.hibernate.hql.ast.QuerySyntaxError: Unable to locate class [<ATransferObject>]


The above is not what I think, but my experience.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 9:33 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
vw729 wrote:
sreepraveen_2000 wrote:
your own object is simply a POJO, i dont think it needs to have any hibernate mapping file.


Thanks again for your information. My question is not about how to write the HQL, but how to let Hibernate know the transfer object class as what I stated clearly in my original question. My understanding is that Hiberante needs to know any classes appeared in HQLs and the only way to let Hibernate know a class definition is to have a class mapping file. If it is not in a mapping file, a Hibernate query exception will occur.

Code:
org.hibernate.hql.ast.QuerySyntaxError: Unable to locate class [<ATransferObject>]


The above is not what I think, but my experience.


Have you tried specifying the whole class name (com.....ATransferObject)?

_________________
hth,
Heinz
Don't forget to rate if this helped


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 12:28 pm 
Beginner
Beginner

Joined: Tue Feb 01, 2005 5:26 pm
Posts: 24
Location: dallas
this will help you

http://forum.hibernate.org/viewtopic.php?t=944963&highlight=querysyntaxerror+unable+locate+class

dont forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 1:40 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
I need to point it out that the HQL in this thread only let Hibernate issue a single SQL statement and fetch data from the Book table only. A join statement is needed in order to fetch data from the Review table as well along with its parent object. This is an information from the reference documentation.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.