Hibernate Class cast expection when reading items from createSQLQuery().list


Got some good advice from https://forum.hibernate.org/viewtopic.php?p=2393573
From
String tableQuery = “Select * from ” + tableName ;
Query tableResult = null;
List table = null;
tableResult = currentSession().createSQLQuery(tableQuery);
table = tableResult.list();

I modified the code to
String tableQuery = “Select {t.*} from ” + tableName + ” t”;
Query tableResult = null;
List table = null;
tableResult = currentSession().createSQLQuery(tableQuery).addEntity(“t”, tableClass);
table = tableResult.list();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s