我在运行以下代码时获得Exception in thread "main" java.lang.ExceptionInInitializerError
public class JPAUtil {
private static final EntityManagerFactory emFactory;
static {
try {
emFactory = Persistence.createEntityManagerFactory("org.hibernate.events");
}catch(Throwable ex){
System.err.println("Cannot create EntityManagerFactory.");
throw new ExceptionInInitializerError(ex);
}
}
public static EntityManager createEntityManager() {
return emFactory.createEntityManager();
}
public static void close(){
emFactory.close();
}
}
堆栈跟踪:
Cannot create EntityManagerFactory.
Exception in thread "main" java.lang.ExceptionInInitializerError
at util.JPAUtil.<clinit>(JPAUtil.java:16)
at event.EventManager.createAndStoreEvent(EventManager.java:30)
at event.EventManager.main(EventManager.java:18)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.hibernate.events
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at util.JPAUtil.<clinit>(JPAUtil.java:13)
... 2 more
请帮助我&amp;告诉我我哪里错了?
答案 0 :(得分:0)
emFactory = Persistence.createEntityManagerFactory("org.hibernate.events");
正确的语法:
emFactory = Persistence.createEntityManagerFactory("org.hibernate.events.jpa");