-->
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.  [ 5 posts ] 
Author Message
 Post subject: selecting from classes as a pojo
PostPosted: Tue Jul 12, 2005 12:55 pm 
Newbie

Joined: Wed Mar 23, 2005 12:09 pm
Posts: 6
Hey all,

I didnt find this in search:

I want to select some field values in a plain old java object that I've defined as MyDTO. It has a constructor that accepts all the values I'm selecting and in that order:

Code:
select new MyDTO ( a.field1, a.field2, b.field1 )
from  AClass a, 
      BClass b
where  a.field4 = b.field4


The error I'm getting is org.hibernate.hql.ast.QuerySyntaxError: Unable to locate class [MyDTO] [

and then the trace, (run from Junit within Eclipse).
What gives here? I have my import set in the dao class just in case. The reason I'm doing it this way is to have a small and convenient class to package and potentially modify the values, and not full the full long fields which includes heavy objects like clobs.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 3:37 pm 
Newbie

Joined: Wed Mar 23, 2005 12:09 pm
Posts: 6
ok I think I've resolved this issue,

you aren't allowed to make it into a pojo, the class you select new as should be a pre-mapped hibernate class.

doh :\

if i have this wrong, please let me know, otherwise, time to dip back into the mapping files :\


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 5:04 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
No, you seem to have it right. It's basically the facade pattern, and you have to map both the parent and the child class as separate types.

I've done this same thing in my own apps to cut down on memory use when I really only want to fetch a few fields for an otherwise large and expensive object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 5:29 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
MyDTO does need to be a real class, with corresponding Hibernate mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 6:37 am 
Newbie

Joined: Wed Mar 23, 2005 12:09 pm
Posts: 6
one final note, this was way easier to fix than i thought,
just added the fields to my premapped class in the existing DTO only and voila, it worked :) (and the constructor of course)

the difference was astounding, let me advise other beginners to not use "from blah" construct directly if you dont have to :)


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