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.
|