Hello,
I'm using JPA with Hibernate. I have a Entity 'Customer' with 30 fields which is mapped to table 'customer_table'. I want all rows but only 2 columns.
In SQL, I would have written a query:
Code:
SELECT customer_id,customer_name from customer_table
In JPA, I wrote:
Code:
Query q = em.createQuery("SELECT c.customerId, c.customerName from Customer c");
List<Customer> customerList = q.getResultList();
for(Customer customer: customerList ){
System.out.println("customer Id=" + customer.getCustomerId() );
}
But when I try to run, I get 'java.lang.
ClassCastException: [Ljava.lang.Object; cannot be cast to entity.Customer'.
Please tell how to resolve this issue.
Thank You.