-->
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.  [ 6 posts ] 
Author Message
 Post subject: Execute SQL statements
PostPosted: Fri Apr 20, 2007 3:09 am 
Newbie

Joined: Thu Mar 29, 2007 3:38 am
Posts: 18
Hi guys :)

I'd like to directly query my DBMS because my business objects are not aware of all their fields... (for confidentiality purposes)

But the problem is that the fields of the retrieved object are empty (but the number of "countries" is correct). It seems that the mapping isn't done any longer when working like that...

Do you know where the problem comes from ?

Thanks ;)

Here's my DAO code :
Code:
public Collection<Country> getCountries() {
    (...)
    String query = "select * from countries";
    SQLQuery sqlQuery = session.createSQLQuery(query);

    return sqlQuery.list();
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 3:48 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
>> return sqlQuery.list();

Try

return sqlQuery.addEntity(Country.class).list() ;

>>> I 'd like to directly query my DBMS because my business objects are not aware of all their fields
If you do not want to map columns to the Model as fields (this is how I interpreted ) you can use Dynamic Models.
---------------------------------------------------------------
Rate the reply if you find it helpful


Last edited by pramodkp on Fri Apr 20, 2007 3:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 3:54 am 
Newbie

Joined: Thu Mar 29, 2007 3:38 am
Posts: 18
Hi pramodkp ! :)

thanks for your answer.

But this doesn't resolve the problem :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 3:59 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
Is Country Mapped correctly ? ( I mean all properties )


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 4:16 am 
Newbie

Joined: Thu Mar 29, 2007 3:38 am
Posts: 18
Yes I think it is,

because when I load all the countries the normal way, it works !


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 4:38 am 
Newbie

Joined: Thu Mar 29, 2007 3:38 am
Posts: 18
resolved ! :)

Simply by using

Code:
        String query = "select * from countries c";
        SQLQuery sqlQuery = session.createSQLQuery(query).addEntity("c", Countries.class);


thanks pramodkp, I rate your answer ! :)


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