-->
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.  [ 9 posts ] 
Author Message
 Post subject: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Tue Sep 28, 2010 5:29 am 
Beginner
Beginner

Joined: Tue Sep 28, 2010 5:14 am
Posts: 25
Hi,

I am trying to use FullTextSession object for hibernate search indexing. But Search.getFullTextSession(session) returns org.hibernate.impl.SessionImpl java.lang.ClassCastException. Not sure what is going wrong. Here is a code snippet :

import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;


public class FirstExample {
public static void main(String[] args) {
Session session = null;
Transaction transaction = null;

try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
FullTextSession fts = Search.getFullTextSession(session);

}catch(Exception e){
System.out.println(e.getMessage()+ " " + e);
}finally{
session.flush();
session.close();

}

}
}


As per compatibility matrix, here are the jar version I am using

hibernate3.jar
hibernate-commons-annotations-3.1.0.GA.jar
hibernate-entitymanager-3.4.0.GA.jar
hibernate-search-3.1.1.GA.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-core-3.3.1.GA.jar
lucene-core-2.4.1.jar

I have tried to debug in the source code but doesn't make much sense for class cast exception.

Thanks in advance.

Cheers
Manoj


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Wed Sep 29, 2010 4:44 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
What's the full stack trace?
Regarding your dependencies -hibernate3.jar is just Hibernate Core. I don't think you need it.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Wed Sep 29, 2010 8:46 am 
Beginner
Beginner

Joined: Tue Sep 28, 2010 5:14 am
Posts: 25
Hi Hardy,

The only exception that I get in stacktrace is ClassCastException: Cannot cast org.hibernate.impl.SessionImpl (id=18) to org.hibernate.event.EventSource. There is nothing more than this in the stacktrace. when I debugged the code right inside the source file of FullTextSessionImpl, I found that the error occurs when it there is type casting of a session object with EventSource.

this.transactionContext = new EventSourceTransactionContext( ( EventSource ) session );

I am just wondering if the there is any problem with the session object that I am trying to create.

Manoj


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Wed Sep 29, 2010 9:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Somewhere there should be more context to this error. Have you checked all log files? Is your application / IDE somehow swallowing the exception somewhere?
My guess would be that you have a wrong setup somehow or class conflicts. Is your application a standalone Hibernate app or are you developing a web or J2EE application? Are you using any additional framework?

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Wed Sep 29, 2010 9:56 am 
Beginner
Beginner

Joined: Tue Sep 28, 2010 5:14 am
Posts: 25
I am using eclipse for development and don't see any problem with logs. I can print stacktrace for other errors I throw explicitly.

But I agree with you, that the project configuration could be an issue or that there might be a class conflict. I am running this as a standalone application and dont have any framework apart from hibernate.This is just like a POC which I am doing before I actually move that to my web application.

However, I have observed that my project doesnt compile without hibernate3.jar and hibernate-core-3.3.1.GA.jar both in classpath. When I remove hibernate3.jar from project, it has issue creating SessionFactory object and throws null pointer exception for session object. If I remove hibernate-core-3.3.1.GA.jar it has issue with the Eventsource object. Does that problem makes sense with the jars I am using ?


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Wed Sep 29, 2010 11:27 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
I have observed that my project doesnt compile without hibernate3.jar and hibernate-core-3.3.1.GA.jar both in classpath

You should remove hibernate3.jar from the classpath, and fix your problems to have it compile properly: you can't have both on classpath as they contain the same classes in different versions, so they're creating a huge mess.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Thu Sep 30, 2010 4:59 am 
Beginner
Beginner

Joined: Tue Sep 28, 2010 5:14 am
Posts: 25
Thanks a lot for all your help. I did resolve this. There was compatibility issue with the hibernate and hibernate search jars that I was using.

But I still fail to understand how there could be issues be Session object in 2 different jars.

--Manoj


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Fri Oct 01, 2010 5:02 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
But I still fail to understand how there could be issues be Session object in 2 different jars.

because you won't control which one you're loading :)
this gets you very randomic and non-predictible issues; this applies to all java applications, with the exceptions of different applications in an application server, but still you have to be careful: be aware of what you do, understand and setup classloader isolation.
If you want to keep it simple, never put duplicate classes in your classpath.

To make sure you don't have more duplicates, use a tool ass JBoss Tattletale http://jboss.org/tattletale, it's a command line tool which inspects your application and produces a great report with warnings about this.
For in depth detaials, see also webinar #8 at : http://www.jboss.org/webinars

BTW if you used Maven to manage your dependencies you would avoid all the mess.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate Search : Classcastexception for FullTextSession
PostPosted: Fri Oct 01, 2010 5:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I also recommend to get an IDE independent build (ant, maven, gradle or whatever you want) with clearly specified dependencies.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.