Getting fewer columns with hibernate
I have a table with 11 columns, but I need to get only 2 of them in my application, I'm using spring/hibernate/DAO combination. For now I have a domain class which includes all 11 fields, and mapping file which maps all 11 columns in table. How do I use get just 2 of them not all? Either: Use projections - Pro: nothing to add - Con: Not typesafe (the result is a List of rows where each row is an Object[]) : select f.foo, f.bar from FatEntity f Use a constructor expression in the SELECT clause (the specified class is not required to be an entity or to be mapped to the database) - Pro: typesafe