我正在尝试通过JPA与mysql db建立连接,但现在让我发疯。 我不知道我是怎么做到的,但是现在当我重复一遍时,我得到了这个异常:
[EL Warning]: metamodel: 2017-10-06 12:04:17.461--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 elements or a global false element
Hello world
Exception in thread "main" java.lang.IllegalArgumentException: NamedQuery of name: Vechicle.findAll not found.
at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:351)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1124)
at javaapplication3.JavaApplication3.main(JavaApplication3.java:28)
这是我的文件:
Persistance.xml
org.eclipse.persistence.jpa.PersistenceProvider
javaapplication3.Bus
javaapplication3.ProductsList
javaapplication3.Worker
javaapplication3.Division
javaapplication3.VechicleType
javaapplication3.Kontrahent
javaapplication3.Vies
javaapplication3.Templ
javaapplication3.DocumentsList
javaapplication3.Vechicle
车辆类
@Entity
@Table(name = "vechicle")
@NamedQueries({
@NamedQuery(name = "Vechicle.findAll", query = "SELECT v FROM Vechicle v"),
@NamedQuery(name = "Vechicle.findById", query = "SELECT v FROM Vechicle v WHERE v.id = :id"),
@NamedQuery(name = "Vechicle.findByNrReg", query = "SELECT v FROM Vechicle v WHERE v.nrReg = :nrReg"),
@NamedQuery(name = "Vechicle.findBySize", query = "SELECT v FROM Vechicle v WHERE v.size = :size")})
public class Vechicle implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
......
}
应用程序类
private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("JavaApplication3PU");
private static EntityManager em = emf.createEntityManager();
public static void main(String[] args) {
System.out.println("Hello world");
em.getTransaction().begin();
List vech = em.createNamedQuery("Vechicle.findAll").getResultList();
em.getTransaction().commit();
}
抱歉,那是一团糟,但这是我第六次尝试弄清楚它,但我不知道这是什么。 其他具有相同配置的应用程序确实运行良好...有人知道我做错了什么吗?