问题描述
Spring.xml<!--......--><beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><propertyname="mappingResources"><list><value>Bean/Person.hbm.xml</value></list></property><propertyname="hibernateProperties"><value>hibernate.dialect=org.hibernate.dialect.Oracle10gDialecthibernate.hbm2ddl.auto=updatehibernate.show_sql=truehibernate.format_sql=false<!--下面为hibernate的二级缓存的配置-->hibernate.cache.use_second_level_cache=truehibernate.cache.use_query_cache=false;hibernate.cache.provider_class=org.hibernate.cache.EhCacheProviderhibernate.search.default.directory_provider=org.hibernate.search.store.FSDirectoryProviderhibernate.search.default.indexBase=./src/Indexes</value></property></bean><!--......-->
Person.javapackageBean;import*****;@IndexedpublicclassPersonimplementsSerializable{@DocumentIdprivateStringid;@FieldprivateStringname;//setter,getter}
Spring+Hibernate是没有问题的。但加入HibernateSearch之后也是没有问题。FullTextSessionfts=Search.getFullTextSession(sessionFactory.getCurrentSession());这样就是不行。报错。org.hibernate.impl.SessionImplcannotbecasttoorg.hibernate.event.spi.EventSource
解决方案
解决方案二:
求回复!
解决方案三:
这个好像是类型转换失败的异常参考:https://forum.hibernate.org/viewtopic.php?f=9&t=1007329&view=previousIamusingeclipsefordevelopmentanddon'tseeanyproblemwithlogs.IcanprintstacktraceforothererrorsIthrowexplicitly.ButIagreewithyou,thattheprojectconfigurationcouldbeanissueorthattheremightbeaclassconflict.Iamrunningthisasastandaloneapplicationanddonthaveanyframeworkapartfromhibernate.ThisisjustlikeaPOCwhichIamdoingbeforeIactuallymovethattomywebapplication.However,Ihaveobservedthatmyprojectdoesntcompilewithouthibernate3.jarandhibernate-core-3.3.1.GA.jarbothinclasspath.WhenIremovehibernate3.jarfromproject,ithasissuecreatingSessionFactoryobjectandthrowsnullpointerexceptionforsessionobject.IfIremovehibernate-core-3.3.1.GA.jarithasissuewiththeEventsourceobject.DoesthatproblemmakessensewiththejarsIamusing?可能和你hibernate版本有点不配合
解决方案四:
对的。是类型转换失败了。我看了上楼发的网址。但是还是没有解决。
解决方案五:
应该用sessionFactory().openSession();