I have a problem with JPA’s persistence.xml
This is the warning that I don't have classes and exception when I try select smth
[EL Warning]: metamodel: 2021-01-26 14:52:53.211-- The collection of metamodel types is empty. Model
classes may not have been found during entity search for Java SE and some Java EE container managed
persistence units. Please verify that your entity classes are referenced in persistence.xml using
either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes>
element
Exception in thread "main" java.lang.IllegalArgumentException: An exception occurred while creating a
query in EntityManager:
Exception Description: Problem compiling [select t from Notatka t].
this is my persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="Notatki" transaction-type="RESOURCE_LOCAL">
<class>test.Notatka</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/test" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
</persistence>
and my main
public class Main {
public static void main(String[] args) {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("Notatki");
EntityManager em = factory.createEntityManager();
Query q = em.createQuery("select t from Notatka t");
List<Notatka> todoList = q.getResultList();
for (Notatka todo : todoList) {
System.out.println(todo);
}
System.out.println("Size: " + todoList.size());
}
}
I think problem is in this line (but I'm not sure)
EntityManager em = factory.createEntityManager();
question from:
https://stackoverflow.com/questions/65902883/illegalargumentexception-an-exception-occurred-while-creating-a-query-in-entity 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…