views:

394

answers:

1

Normally, I use Glass Fish as my testing server for NetBeans. Recently, I tried to switch to Tomcat 6.0. As soon as I changed the server, compiler no longer understand javax.persistence.Entity. When I checked out the library structure of Tomcat 6.0, there was a file named annotation-api.jar, in which another javax.persistence package resides (!!!). Is it possible to resolve this kind of conflict, which there are two package with different contents share the same name?

+2  A: 

The annotation-api.jar is not a JPA implementation. There is no means of collisions in classpath as you seem to think (that would have produced runtime errors rather than simple compilation errors). Tomcat doesn't have any JPA implementation while Glassfish has one built-in. You need to provide one yourself. You can choose of under each OpenJPA, Hibernate, TopLink or EclipseLink. And ensure that you placed it in Webapp/WEB-INF/lib.

BalusC
I don't even know where the standard javax.persistence package located in, look like it's from JDK (?), but I cannot find it inside the navigation tree of JDK package. By the way, it's true that annotation-api.jar is not a JPA implementation, but it contains a package named javax.persistence that confuse the compiler because now compiler cannot locate javax.persistence.Entity class anymore (which is required for my Hibernate mapping). Normally, I put all jar files in Libraries section of my project and have Netbeans deploy them automatically, is there any thing wrong with this?
Mr Cold
This is not true. It does not confuse the compiler. Tomcat simply doesn't ship with a JPA implementation like Glassfish does. Tomcat is a simple JSP/Servlet webcontainer, while Glassfish as being an worthfully Java EE application server implements pretty much all of the Java EE spec, including JPA. You'll provide a JPA implementation yourself. Place it in `Webapp/WEB-INF/lib`. Netbeans is irrelevant here, it's just a development tool.
BalusC
Please have a look at this screen capturehttp://seamoo.com/Tomcat-Hibernate-Messed-Up.jpgDo you see the javax.persistence is included, and the Entity annotation is nolonger understood by the IDE? I know that Netbeans is a IDE, but it reflect the mechanism underlying it, right?What is your explanation for this problem?
Mr Cold
I think you unfortunately didn't understand me. I'll tell you once again in short: Tomcat does NOT ship with a JPA implementation. You need to provide one yourself. That's all. You cannot get cold air in a car without a built-in airco.
BalusC
Oh, I got that. It's look like Glass Fish was shipped with a JPA implementation while Tomcat was not. I add Hibernate JPA to my project and every thing is fine now. Thank you.
Mr Cold