-->
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.  [ 4 posts ] 
Author Message
 Post subject: column aliases for non-managed entities
PostPosted: Mon Dec 04, 2006 11:05 am 
Newbie

Joined: Fri Apr 28, 2006 11:26 am
Posts: 8
Location: Vancouver, WA
Section 16.1.5 from the Hibernate (3.2) Reference Guide shows an example of using a ResultTransformer on the results of a SQL query to populate the properties of a non-managed entity. This is almost exactly what I need to do, but I need to also specify an alias to map between a field in the result set and a property of the bean (specifically, I need to map a column named "sub_type" to a field named "subType"). It seems like this should be fairly simple, but I am at a loss.

Any help would be appreciated...thanks!

Tim


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 11:37 am 
Newbie

Joined: Fri Apr 28, 2006 11:26 am
Posts: 8
Location: Vancouver, WA
Does anyone have any thoughts on this? Basically, I want to do something like this:

session.createSQLQuery("select id, sub_type from my_table").setResultTransformer(Transformers.aliasToBean(MyTableBean.class));

...except I need a way to map the "sub_type" column in the result set to a field named "subType" in the bean class. Putting the alias directly in the sql ("select ... sub_type as subType") does not work-- I get an error saying that there is no "setsubtype()" method (the aliasing does not preserve the camel-case).

This seems like it should be as common and easy with non-managed entities as it is with managed entities, but I can't seem to figure it out!

Any suggestions would be very much appreciated; this has really got me hung up right now!

Thanks,
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 11:35 am 
Newbie

Joined: Fri Apr 28, 2006 11:26 am
Posts: 8
Location: Vancouver, WA
Since I didn't get any replies and couldn't find any other way to accomplish what I needed to do, I ended up writing a custom ResultTransformer which uses annotations on the properties of the non-managed entity to provide the alias between the result set column and the appropriate property. If anyone is interested in the code, let me know and I'll post it or send it to you.

Thanks,
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 1:26 pm 
Newbie

Joined: Wed May 25, 2005 1:47 pm
Posts: 9
I'm trying to do something very similar and would very much like a look at your code.

Thanks,

Tom


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