Question

I'm quite new to the Java EE persistence world, so I apologize if the question seems odd. In Servlets 3.0 one can eliminate the web.xml file completely and strictly use annotations instead. Can you do this with JPA as well? I've been reading all sorts of things about EntityManagerFactory and PersistenceProvider and so forth so I'm just sort of curious.

Is a way to eliminate the xml files completely and just use subclasses and annotations instead?

Side Note: Preferably, I'd like to stay away from external third-parties such as Spring, though if the solution only exists for them, I'll humbly receive the knowledge.

** EDIT: Removed "hibernate" from list of third-parties.

Was it helpful?

Solution

For simple web applications, web.xml is not required as Servlet spec 3.0 attempts to de-emphasize deployment descriptors. For JPA applications, persistence.xml is required.

For those interested in the details, the sources below describe the above statement:

Servlet 3.0: spec states the following about web.xml:

Section 10.13, “Inclusion of a web.xml Deployment Descriptor” was added which removes requirement for Java EE compliant web applications. The section is as follows:194 Java Servlet Specification • November 2009 A web application is NOT required to contain a web.xml if it does NOT contain any Servlet, Filter, or Listener components. In other words an application containing only static files or JSP pages does not require a web.xml to be present.

JPA 2.0: spec states the following about persistence.xml:

The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit. A persistence unit is defined by a persistence.xml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top