-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: What is an instance if not an instance?
PostPosted: Mon Jul 01, 2013 2:54 pm 
Newbie

Joined: Wed Sep 10, 2008 2:02 pm
Posts: 14
Location: NJ
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.