-->
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: How to get getResultList() to return a table object
PostPosted: Fri Jul 10, 2009 4:28 am 
Newbie

Joined: Fri Jul 10, 2009 3:50 am
Posts: 1
Hi,
I'm going to ask newbie questions so bear with me pls :)

I'm using JPA, Hibernate and DAO. I have the following classes
1) Car - database model
2) CarDAO - interface to CarDAOImpl
3) CarDAOImpl - All the SQL resides in here

I have the following method in my CarDAOImpl
Code:

@Transactional(propagation = Propagation.MANDATORY)
    public List<Car> getAll() {
        @SuppressWarnings("unchecked")
        List<Car> result = getEntityManager().createQuery(
        "SELECT r FROM Car r ORDER BY r.carModel").getResultList();
        return result;
    }


The HQL above queries everything from the Car table. When I execute this method, the getResultList() will return a list of Car objects which is cool.

But when I changed the HQL to the following, I didn't get the Car object anymore, instead result contains a list of Object[].

Code:

@Transactional(propagation = Propagation.MANDATORY)
    public List<Car> getAll() {
        @SuppressWarnings("unchecked")
        List<Car> result = getEntityManager().createQuery(
        "SELECT r.carModel, r.yearManufactured FROM Car r ORDER BY r.carModel").getResultList();
        return result;
    }


My question is how do I get a list of Car objects when I'm specifying columns to query from database? Is this not possible?

Any suggestions are welcome. Thanks in advance


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.