Reputation: 11
Yes I've already searched here for this question but I have this problem after the researches.
So, I'm making a simple standalone project, containing only Entities and DAOs. I'm using IntelliJ.
EDIT: My DB connection informations are good, I'm sure. And I've got another project (GWT) and I'm using the same method -> it works
My META-INF folder is in the root src folder, so this is my persistence.xml:
`<persistence-unit name="jpa">
<!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<class>ejbpersistance.entities.User</class>
<class>ejbpersistance.entities.Comment</class>
<class>ejbpersistance.entities.Article</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/ejb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>`
and this is my code:
public EntityManagerFactory getEntityManagerFactory() {
if(emf == null)
emf = Persistence.createEntityManagerFactory("jpa");
return emf;
}
I tried with Hibernate provider, Eclipse provider but always this problem. Can someone help me ? And if I missed something in another topic concerning this issue, I apologize for the time loss.
Upvotes: 1
Views: 891
Reputation: 74028
Make sure persistence.xml
is in the META-INF
directory and the class path includes the META-INF parent directory.
You also didn't show the complete persistence.xml
. The surrounding <persistence>
tag must include the proper namespace, e.g.
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence">
...
</persistence>
Upvotes: 1
Reputation: 423
The location of the persistence unit is the issue here.
check if persistence.xml is in your classpath: If it is non-Java EE application(j2SE)
The jar file or directory whose META-INF directory contains the persistence.xml file is termed the root of the persistence unit.please check classpath location in your IDE, Eclipse: Project Properties -> Java Build Path -> ****.
check if hibernate provider is in your classpath once you can try to uncomment the provider line in your P.xml file org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
Thanks
Upvotes: 1