Hello!
I am not exactly sure what is wrong in your app, but...
To query database I use EntityManager. I get EntityManager either by injecting EntityManagerFactory or EntityManager itself.
To be able to inject EntityManager or EntityManagerFactory I should configure correctly PersistenceUnit. To configure PersistenceUnit I should set up
persistence.xml which should be for my
Maven projects in src/main/resources/META-INF directory.
The correct persistence.xml for me looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="OlympicsPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/olympicsDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/olympics?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.password" value="123456"/> //here your password for mysql should be
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/> //here your username for mysql should be
</properties>
</persistence-unit>
</persistence>
I usually allow netbeans to create persistence.xml for me by clicking yellow lamp next to name of entity. Therefore I don't get into many problems with PersistenceUnit.
Your error is java.lang.NoClassDefFoundError: org/hibernate/proxy/EntityNotFoundDelegate
I suppose that not found entity simply is not declared in persistence.xml by element <class>com.olympics.entities.Competition</class> OR by
<exclude-unlisted-classes>false</exclude-unlisted-classes> - it includes all entities.
If you are not familiar well with persistence.xml then look at given one, each line is important especially this:
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">