Hi there!

Hi there!
My name is Michael Ivanov and i'm a Senior SDE/Software architect.
My CV - here. You can find articles and other blog posts on the main page. I also develop some free and commercial software - complete list is here.

Friday, January 6, 2012

persistence.xml within "Dynamic Web Project" in eclipse

Being totally newbie at j2ee area, i decided to spent some time looking through the area and to get familiar with appropriate technologies. After reading about odata and servlets, i decided to build a simple servlet to return some odata block. I created Dynamic Web Project and used odata4j to return appropriate producer. But i met some problems that took me 3 days to serve.
In Java (as you probably know) is a standartized API named JPA, that describes a set of notations for ORM (Object-relation mapping). You configure your future mapping with a special file, named persistence.xml (and no other names should be used). All articles i looked through (well, may it was my mistake - i just looked through all manuals) told me to put this file in the /WebContent/META-INF directory. I did it and after deploying to my tomcat (integrated in eclipse) i got
root cause

java.lang.RuntimeException: javax.persistence.PersistenceException: No Persistence provider for EntityManager named TaskPersistanceUnitName
org.odata4j.producer.resources.ODataProducerProvider.newProducerFromFactory(ODataProducerProvider.java:65)
org.odata4j.producer.resources.ODataProducerProvider.getInstance(ODataProducerProvider.java:45)
org.odata4j.producer.resources.ODataProducerProvider.getInstance(ODataProducerProvider.java:15)
com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider.get(LazySingletonContextProvider.java:83)
com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider.access$000(LazySingletonContextProvider.java:55)
com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider$1.getValue(LazySingletonContextProvider.java:72)
com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable$1.getValue(AbstractHttpContextInjectable.java:104)
com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)


I spent several days trying to figure out the reason of such behavior, and finally i read carefully http://javahowto.blogspot.com/2007/06/where-to-put-persistencexml-in-web-app.html
i created folder META-INF inside WebContent/WEB-INF/classes
and got it works

No comments: