This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes entity loading blues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "entity loading blues" Watch "entity loading blues" New topic
Author

entity loading blues

Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
I got this scenario:
a query from wich i need to return a list of beans, that i don't want persisted.

The question is:
Can i do that directly speifying the bean like:

w/o having to map the Person to a table?

Closest answer for that from what i found is the one below, but i need to know the answer to the above question, it makes the following solution redundant.
EDIT: shortest question would be: how can i externalize a named query w/o an entity, and also map the result set to a bean with the least configuring possible.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Well, the only way to populate non-entity beans is to use Transformers.aliasToBean() it seems. BTW, it only accepts the column name, not an alias of it. It only needs matching type with the bean fields / public accesor methods.

Otherwise externalizing a SQL query, is as simple as:


and registering it in the hibernate config file.
Shaun M. Smith
Greenhorn

Joined: Jul 06, 2010
Posts: 1
Seeing your posting I blogged about how to do this in EclipseLink here: http://onpersistence.blogspot.com/2010/07/eclipselink-jpa-native-constructor.html

--Shaun
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: entity loading blues
 
Similar Threads
long post IBM.158
Question about Inherited Tables and Relationships
org.hibernate.QueryException!
need help in EJB QL with upper and like
JPA native query, group function, different entity