5

I have class that uses hibernate, I have included all required jars to classpath and class worked before Java updated itself. But now eclipse shows that it cannot resolve some hibernate imports. What could be solution to this?

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
newbie
  • 24,286
  • 80
  • 201
  • 301

6 Answers6

7

Delete .m2/repository/org/hibernate/*, then in eclipse: Maven/update Project. It will download the dependencies again. It worked for me!

Duc Dat Nguyen
  • 359
  • 4
  • 7
5

Did you try "Project > Clean ..."? What is the exact error message? After a Java update, you might need to update the path to the JDK: "Window > Preferences > Java > Installed JREs"

sfussenegger
  • 35,575
  • 15
  • 95
  • 119
  • The import org.hibernate.SessionFactory cannot be resolved and same for other hibernate classes – newbie Jan 23 '10 at 08:54
  • Sounds really strange. Sorry, I don't have any good ideas on how to proceed. Maybe try to write a new class and import these two classes. Or remove the imports and use "Organize Imports" to automatically add them again. Try restarting eclipse, closing and reopening the project ... well, no rocket science here, but maybe ... – sfussenegger Jan 23 '10 at 10:38
  • 1
    I removed all jars and downloaded them again and then added jars to project, and now there is no problmes, very strange indeed – newbie Jan 23 '10 at 11:01
  • This is a glitch in eclipse. Most of the time cleaning and refreshing the project is enough, but sometimes it is necessary to remove and re-add the jars from the build path to force eclipse to re-evaluate the path. I doubt that downloading the jars again actually changed anything. – Yoni Jan 23 '10 at 13:06
5

If you type (Ctrl + shift + t), or open the Type Explorer and type SessionFactory or Configuration does Eclipse find them? If not, then for sure you have some problems in the .jar files. Try to delete and replace them.

By the way are you using a Mac or PC?

gary
  • 4,227
  • 3
  • 31
  • 58
Omar Al Kababji
  • 1,768
  • 4
  • 16
  • 31
2

I experienced a similar problem that got fixed when I used Grails Tools > Refresh Dependencies (Alt+G,R). This was in SpringSource Tool Suite 2.7.1.

I had to run that once to get the plugins to initialize correctly (after an import from SVN) and then a second time to get references to work.

Gene Golovchinsky
  • 6,101
  • 7
  • 53
  • 81
0

even i was facing the same problem . every thing was working fine but all of a suden every jsp page started giving me error saying org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 1 in the generated java file The type org.hibernate.SessionFactory cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: 9 in the generated java file Only a type can be imported. org.hibernate.Query resolves to a package

An error occurred at line: 11 in the generated java file Only a type can be imported. org.hibernate.Session resolves to a package

An error occurred at line: 12 in the generated java file Only a type can be imported. org.hibernate.SessionFactory resolves to a package

An error occurred at line: 13 in the generated java file Only a type can be imported. org.hibernate.cfg.Configuration resolves to a package

to solve thi problem in eclipse i removed/deleted the server from eclipse and added my tomcat server back and every thing started working same as before .....

Thanks

0

I faced this problem today.I think eclipse tell me that he want to resolve something but don't know what problem and how.And here it is:

SessionFactory factory;
    try {
        factory = new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) { 
        System.err.println("Failed to create sessionFactory object." + ex);
        throw new ExceptionInInitializerError(ex); 
    }

Maby it helps.In my case it was exception handling.

Scoots
  • 3,048
  • 2
  • 21
  • 33