问题
Above exception has been throwing While creating a hibernate session factory.
In application lib folder have hibernate-jpa-2.1-api and javax.persistence.2.1.0. I can able to see the NamedStoredProcedureQuery class in both jar. But I am getting runtime error for classnotfoundexception. Any suggestion?
回答1:
NamedStoredProcedureQuery class is available in hibernate-jpa-2.1-api jar. But this jar refers some other jar in run time. So I didn't get error in compile time and getting exception during runtime. I just added other hibernated libs through maven repository.Initially i used only hibernate-core. Now artifactIDs are hibernate-core,hibernate-validator,hibernate-commons-annotations,hibernate-jpa-2.0-api and hibernate-entitymanager.
回答2:
I have a non-ideal solution. I ended up using hibernate-core 3 (3.6.10) which doesn't throw the same error.
I got this idea from Mario Schwaiger, CodeRanch, for a different, but similar, class not found exception: http://www.coderanch.com/t/509836/ORM/databases/Hibernate-java-lang-ClassNotFoundException-javax
Details: I'm doing something slightly different - integrating Hibernate 4 with Struts 1 (instead of Spring), but ran into the same NamedStoredProcedureQuery class not found problem. Adding hibernate-validator threw different errors. Other things that did not work for me were: adding hibernate-entitymanager, adding javax.persistence, and changing tomcat or eclipse java versions between Java 8 and 7.
You'll need to instantiate the sessionfactory differently between Hibernate 3 and 4.
Hopefully somebody will post a better solution to your Spring problem.
回答3:
You have to add hibernate-entitymanager to your classpath.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
来源:https://stackoverflow.com/questions/28247750/java-lang-classnotfoundexception-javax-persistence-namedstoredprocedurequery