-->
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.  [ 3 posts ] 
Author Message
 Post subject: Access to org.hibernate.Session: ClassCastException
PostPosted: Sun Apr 23, 2006 11:04 am 
Beginner
Beginner

Joined: Mon Dec 05, 2005 4:15 am
Posts: 36
I read the section 2.3 of JBoss EJB 3.0 Reference Documentation:
Quote:
You can get access to the current underlying Hibernate Session by typecasting your reference to EntityManager.

@PersistenceContext EntityManager entityManager;
public void someMethod();
{
org.jboss.ejb3.entity.HibernateSession hs = (HibernateSession)entityManager;
org.hibernate.Session session = hs.getHibernateSession();
}



But, if I made a typecast to HibernateSession in my program, I get a ClassCastException, because my EntityManager is an instance of the class org.hibernate.ejb.EntityManagerImpl which cannot be casted to HibernateSession.
I use Hibernate 3.1 and EJB3.0RC5.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 9:08 am 
Newbie

Joined: Tue Jan 03, 2006 7:30 am
Posts: 18
Location: Budapest, Hungary
Try something like
Code:
session = ((HibernateEntityManager) entityManager.getDelegate()).getSession();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 9:35 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Just simply use like this:

Code:
@PersistenceContext Session session;


JBossAS EJB3 container will inject you a Session instance instead of EM instance.


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

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.