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: help with aliasToBean Transformer
PostPosted: Tue Oct 20, 2009 2:05 pm 
Newbie

Joined: Tue Oct 20, 2009 1:50 pm
Posts: 1
I am having a problem populating beans with the results from a sql query.

I have a User bean, a User table, and a User_history table. I would like to get a list of User objects as a result of querying the User_history table. The problem is that while the User objects have properties such as createDate, or legalName, the DB has columns named "create_date" and "legal_name". When I am just populating a User object from the User table, it works fine based on the @Column annotations in the User class. When I try to populate the User objects based on a "Select * from User_history", I get "cannot find a setter for create_date" error.

The code I am currently using for pulling the list is:

String sql = "SELECT * FROM User_history WHERE ID=" + id + " ORDER BY version";
Query query = session.createSQLQuery(sql)
.setResultTransformer(Transformers.aliasToBean(User.class));
List trail = query.list();


How do I resolve the missing setter issue? Is there a way to tell the transformer what columns map to what?

I also tried specifically writing out the individual column names and providing aliases for them, but then I get a class cast exception when it tries to populate the id field for the User since the User.id is a Long and the database uses a BIGINT.


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.