Class cast exception in org.hibernate.search.impl.FullTextSessionImpl<init>(FullTextSessionImpl.java:54)

Description

This issue is also documented in the following thread, but no-one has replied to the original author.
http://forum.hibernate.org/viewtopic.php?t=968907&highlight=fulltextsessionimpl

The following class cast exception occurs inside org.hibernate.search.impl.FullTextSessionImpl.

java.lang.ClassCastException: org.jboss.ejb3.entity.TransactionScopedHibernateSession incompatible with org.hibernate.impl.SessionImpl
at org.hibernate.search.impl.FullTextSessionImpl.<init>(FullTextSessionImpl.java:54)
at org.hibernate.search.Search.createFullTextSession(Search.java:17)

This happens because FullTextSessionImpl's constructor is casting the org.hibernate.Session interface passed as an argument to the constructor to org.hibernate.impl.SessionImpl. Of course the jboss class TransactionScopedHibernateSession is not an instance of SessionImpl.

public class FullTextSessionImpl implements FullTextSession {

private final SessionImpl session;

private PostTransactionWorkQueueSynchronization postTransactionWorkQueueSynch;

public FullTextSessionImpl(Session session) {

this.session = (SessionImpl) session;

}
...

Also, the method createFullTextQuery constructs an instance of FullTextQueryImpl with the session that the FullTextSessionImpl was instantiated with. The FullTextQueryImpl constructor expects to receive an instance of org.hibernate.engine.SessionImplementor. TransactionScopedHibernateSession and the interface org.hibernate.Session do not implement this interface.

The following link is an issue in jira for JBoss EJB 3 about the fact it doesn't support SessionImplementor. Though I don't know if JBoss should implement this interface or not - it may well be bad design for JBoss to implement this just to get it working and perhaps some hibernate refactoring is needed to sort these issues out instead.

http://jira.jboss.com/jira/browse/EJBTHREE-714

FYI the class definition of TransactionScopedHibernateSession is as follows...

public class TransactionScopedHibernateSession implements Session, Externalizable
{
...
}

This is critical since the search functionality in 3.2.1GA of annotations cannot be used in JBoss as the Session is proxied by TransactionScopedHibernateSession.

Environment

JBoss 5.0.0 Beta1, Hibernate 3.2.2 GA, Hibernate Annotations 3.2.1 GA, Hibernate Entity Manager 3.2.1 GA

Status

Assignee

Emmanuel Bernard

Reporter

AdrianA

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Fix versions

Affects versions

HAN-3.2.1 (Previous Bundled)

Priority

Critical