Hi. I seem to have got my application up and running in JBoss AS 7.1.1 with Hibernate 4.2 (I think). This is an app that I'm in the process of migrating from JBoss 4.2.2 and Hibernate 3.2 (probably).
I'm looking at my code in a debugger where I retrieve an instance of a persistent entity. My code used to look like this:
public Banner getTopNavBarBanner() { Banner answer = null; try { Session hbmSession = HomeFactory.getInstance.lookupHibernateSessionFactory().getCurrentSession(); return (Banner) hbmSession.getNamedQuery(Banner.NamedQuery.GetTopNavBarBanner.getQueryName()) .setMaxResults(1) .uniqueResult(); } catch (Exception e) { log.error("Failed getting content for topNavBar banner.", e); } return answer; }
Now it looks like this:
public Banner getTopNavBarBanner() { Banner answer = null; try { Session hbmSession = (Session) em.getDelegate(); answer = (Banner) hbmSession.getNamedQuery(Banner.NamedQuery.GetTopNavBarBanner.getQueryName()) .setMaxResults(1) .uniqueResult(); } catch (Exception e) { log.error("Failed getting content for topNavBar banner.", e); } return answer; }
I am catching a ClassCastException in the try/catch block. It tells me that com.app.hbm.model.Banner cannot be cast to com.app.hbm.model.Banner. I have inspected the value returned by uniqueResult and I can see in the debugger that it is an instance of com.app.hbm.model.Banner (by highlighting the code and evaluating it), which I think is strange because I expect that the runtime thinks it is an Object. So, something somewhere is turning it into a Banner, but I can't treat it as such and I can't cast it to one. What am I dealing with here? Is this a proxy that knows how to fake out my debugger? How can I turn it into an instance of my model?
Thanks.
|