Hello everyone!
I'm struggling to figure out how to extract data from particular columns from DB. Here is what I have...
A table PersData with columns A, B, C, D and so forth. Also there is an entity represents this table called PersonalData.
I need to get the data from A and C columns, but I still haven't found a solution how to do this. I know how to exctract an entire row from the PersData table by writing the following code...
Query query = entityManager.createNativeQuery("SELECT * FROM 'PersData` ", PersonalData.class);
List<PersonalData> qresult = query.getResultList();
for(PersonalData item: qresult){
System.out.println(item.getA());
.....
... But it's inefficient to get values of other columns at the same time.
I guess that my query should be written smth like this...
Query query = entityManager.createNativeQuery("SELECT A, C FROM `PersData` ");
List<PersonalData> qresult = query.getResultList();
for(PersonalData item: qresult){
System.out.println(item.getA());
.....
But I got an error
java.lang.ClassCastException when I do this for (PersonalData item: qresult). Actually, I understand why it's like this.
Does anybody know how to get values just from two columns and then use them?