2

I had a working java project, I decided to remove all the Server Runtime Environments in my eclipse. since i am getting many errors like :

The import javax.persistence cannot be resolved

,

Entity cannot be resolved to a type

... can I restore the state of my project ?

After thinking in logical reason , I think that the prbolem issued after that I had edited the PATH Variable in windows , can someone tell me what I shouldhave in this PATH variable to get the package javax.persistence working ?

majd hwas
  • 95
  • 2
  • 2
  • 10

3 Answers3

2

To resolve: "The import javax.persistence cannot be resolved" you need to add the jar containing javax.persistence.Entity to your path. It is probably the hibernate-jpa-version-api jar.

To do this in Eclipse:

  • select the project from the Navigator or Package Explorer view
  • From the project menu at the top of the screen select properties
  • Click on Java Build Path and in the libraries tab add the peristence jar
  • Click OK

This should resolve the dependency issue you are having. If you want to add a server, go to file->new->other->server. Then choose the type of server you need.

Brod
  • 1,377
  • 12
  • 14
  • thanks Brod for this reply , so now I am sure that this is the problem that I have , I confirm that the project miss something that I had deleted from the Path variable , can you help me after this details ? – majd hwas May 04 '16 at 15:33
  • Yes, follow the steps above. You simply need to know where the persistence jar is located. Have you tried the steps I listed above in the bullets? What isn't clear? Also checkout this other post: http://stackoverflow.com/questions/15598210/the-import-javax-persistence-cannot-be-resolved – Brod May 04 '16 at 15:45
  • Ok, I am not working with hibernate but with JPA , this issue started when I had deleted something from the path variable, can you guide me what i should have in this variable ? – majd hwas May 04 '16 at 15:53
  • If you are not using hibernate then you may be looking for the persistence.jar. If you don't have persistence.jar or don't know where it is you can download it, then put it in a lib folder in your project and then follow the steps above. If you are using maven, just add it as a dependency. You can find the jar here: http://mvnrepository.com/artifact/javax.persistence/persistence-api/1.0.2 – Brod May 04 '16 at 16:04
  • Another option, if you right click on your .classpath file and choose Compare With->Local History then look at the diffs from the different version. You should find the missing entry in your classpath this way. – Brod May 04 '16 at 17:17
  • Ok , this seems to be good solution, but Where do i find this .classpath file with eclipse ? – majd hwas May 05 '16 at 09:15
  • The classpath should be in the root of your project – Brod May 06 '16 at 16:11
1

I have downloaded the latest Hibernate version & I got the same issue after I added the below jars only, to my project.

Folder: hibernate-search-5.8.0.Final\dist\lib\required

Jars:

/antlr-2.7.7.jar
/classmate-1.3.0.jar
/dom4j-1.6.1.jar
/hibernate-commons-annotations-5.0.1.Final.jar
/hibernate-core-5.2.11.Final.jar
/javassist-3.20.0-GA.jar
/jboss-logging-3.3.0.Final.jar
/lucene-core-5.5.4.jar
/lucene-queryparser-5.5.4.jar
/xml-apis-1.3.03.jar

At this stage I'm facing the below issue.

The type javax.persistence.PersistenceException cannot be resolved. It is indirectly referenced from required .class files

So I have added one more dependent jar where the code is referencing internally and the issue vanished. Folder: hibernate-search-5.8.0.Final\dist\lib\provided

Jar Name: hibernate-jpa-2.1-api-1.0.0.Final.jar

Please post your comments, if you have any doubts and I'm glad to answer.

Suresh
  • 1,491
  • 2
  • 22
  • 27
0

I have just now arrived tofind the solution to my issue, It is because I deleted the Runtime from my project , so I had added new runtime and affected my project toIt and worked fine. Thanks all !

majd hwas
  • 95
  • 2
  • 2
  • 10